I’m trying to catch a Queue.Empty exception that is raised if a multiprocessing.Queue is empty. The following does not work:
import multiprocessing
f = multiprocessing.Queue()
try:
f.get(True,0.1)
except Queue.Empty:
print 'foo'
This gives me a name error: NameError: name ‘Queue’ is not defined
replacing Queue.Empty with multiprocessing.Queue.Empty does not help either. In this case it gives me a “AttributeError: ‘function’ object has no attribute ‘Empty'” exception.
The
Emptyexception you’re looking for isn’t available directly in themultiprocessingmodule, becausemultiprocessingborrows it from thequeuemodule (which used to be namedQueuein Python 2). To make your code work, just do animport queueat the top:Try this: