Vì một số lý do tôi không thể truy cập ngoại lệ Queue.Empty
- tôi đang làm gì sai ở đây?Không thể truy cập Queue.Empty: đối tượng "AttributeError: 'function' không có thuộc tính 'Empty'"
from multiprocessing import Process, Queue
# ...
try:
action = action_queue.get(False)
print "Action: " + action
except Queue.Empty:
pass
Các stack trace:
Traceback (most recent call last):
File "C:\Program Files\Python27\lib\multiprocessing\process.py", line 258,
in _bootstrap
self.run()
File "C:\Program Files\Python27\lib\multiprocessing\process.py", line 114,
in run
self._target(*self._args, **self._kwargs)
File "D:\Development\populate.py", line 39, in permutate
except Queue.Empty: AttributeError: 'function' object has no attribute 'Empty'
Ah tôi thấy bây giờ, tôi nghĩ rằng nhập hàng đợi nhập khẩu mô-đun, chứ không phải là lớp. Cảm ơn! – Ross
thậm chí còn thú vị hơn - việc nhập khẩu 'từ việc xử lý hàng đợi nhập khẩu đa' nhập hàm Queue từ' __init __. Py' trong phép đa xử lý trả về lớp Queue từ mô đun phụ multiprocessing.queues. Cách gõ vịt và không gian tên giúp lập trình thú vị! – underrun