python - python的multiprocessing Queue默认是 "infinite"吗?

标签 python python-3.x python-3.6 python-multiprocessing python-multithreading

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().

所以没有参数(或负数)它可以取无限个元素

(作为旁注,因为队列在内部是类似列表的结构(dequeueheapqlist)限制,然后没有限制。)

编辑:

好的,查看源代码后发现,如果没有指定值,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/

相关文章:

python-3.6 - 带有 `str.__len__(x) == 2` 的单个(重音)字符

python - 正则表达式匹配非字母字符(复合词的连字符除外)

python - 表达式中的临时名称

Python 3.6 urllib 类型错误 : can't concat bytes to str

python - NLTK 命名实体识别数据集中的列

python - 如何在 Windows 上使用 Python 3 连接到 MySQL?

python - 如何重载运算符 `in`?

python - 在pandas python中按列号读取csv文件

python - 如何允许 API 远程访问我的代码而不泄露它?

Python __getattr__ 执行多次