python 的多处理队列的文档:https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue
不像队列那样清楚。队列:https://docs.python.org/3/library/queue.html
关于当未将 maxsize 参数提供给构造函数时,队列的大小是否“无限”(例如,在程序可以设法明智地分配内存的任何可能范围内)。
是这样吗?
最佳答案
multiprocessing.Queue
完全模仿 queue.Queue
的所有功能(.task_done()
和 .join()
)
Queue implements all the methods of Queue.Queue except for task_done() and join().
所以没有参数(或负数)它可以取无限个元素
(作为旁注,因为队列在内部是类似列表的结构(dequeue
、heapq
、list
)限制,然后没有限制。)
编辑:
好的,查看源代码后发现,如果没有指定值,multiprocessing.Queue
确实有一个标准的上限:2**31-1
# file multiprocessing/queues.py class Queue(object): def __init__(self, maxsize=0, *, ctx): if maxsize <= 0: from .synchronize import SEM_VALUE_MAX as maxsize # -> 2**31-1
所以它不是无限的,而是实际上无限的
关于python - python的multiprocessing Queue默认是 "infinite"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50269701/