pyspider源码-schuduler.py之deque

import itertools
import json
import logging
import os
import time
from collections import deque

from six import iteritems, itervalues
from six.moves import queue as Queue

from pyspider.libs import counter, utils
from pyspider.libs.base_handler import BaseHandler
from .task_queue import TaskQueue

from collections import deque

deque

Returns a new deque object initialized left-to-right (using append()
) with data from iterable. If iterable is not specified, the new deque is empty.
Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
Though list
objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0)
and insert(0,v)
operations which change both the size and position of the underlying data representation.

返回一个新的先进先出的列表对象 ,如果没有声明,这个列表是空的.

Deques是线程安全的.和list支持一样的操作.

from collections import deque 
for each in deque('asdfs'):
    print each

run

a
s
d
f
s
[Finished in 0.0s]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容