1 回答

TA貢獻(xiàn)1982條經(jīng)驗 獲得超2個贊
隊列長度為 1,它會根據(jù)需要阻塞
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> import select
>>> import time
>>>
>>> q = multiprocessing.Queue(maxsize=1)
>>> q.put(9)
>>> q.put(10) // blocking here, have to ctrl-c to escape
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/multiprocessing/queues.py", line 101, in put
if not self._sem.acquire(block, timeout):
KeyboardInterrupt
>>>
- 1 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報