多进程的 Spawn.Process 在 Python 中未正确填充队列
我目前正在用 Python 编写一个用于压力测试的连接管理器,看起来我的队列永远不会填满。这个伪代码会比我更好地解释它:
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 is 0
Can无论如何解释为什么我的队列大小为0?
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 is 0
Can anyway explain why my queue has a size of 0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于processQueue.qsize,请注意文档说:
所以您不应该依赖qsize来告诉您队列是否为空。
另外,由于您可能在调用
processQueue.put
之前到达processQueue.qsize
行,因此队列此时可能确实是空的但不会永远空虚。Regarding
processQueue.qsize
, note that the docs say :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 theprocessQueue.put
is called, the queue may indeed be empty at that moment but not empty forever.