开发者

Spawn of a multiprocess.Process is not filling Queue correctly in Python

I am currently writing a connection manager for a stress test in Python it seems my queue is never filling up. This pseudoesque-code will explain it better than I can:

def wget(processQueue)
    currProcess = subprocess.Popen(./wget)
    processQueue.put(currProcess)

def connection(processQueue)
    process = multiprocessing.Process(target=wget, args=(processQueue,))
    process.start()

processQueue = Queue.Queue()
newConnection = multiprocessing.Process(target=connection, args=(processQueue,))
newConnection.start()
processQueue.qsize() # This i开发者_StackOverflow中文版s 0

Can anyway explain why my queue has a size of 0?


Regarding processQueue.qsize, note that the docs say :

Definition: processQueue.qsize(self)
Docstring:
    Return the approximate size of the queue (not reliable!).

so you shouldn't rely on qsize to tell you if the queue is empty.

Also, since you may be reaching the line processQueue.qsize before the processQueue.put is called, the queue may indeed be empty at that moment but not empty forever.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜