Python Forum

Full Version: Multiprocessing queue catch get timeout
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I have a simple script that waits for a queue with a timeout. I would like to catch that specific exception but cant find the correct one.
import multiprocessing as mp
RQ = mp.Queue()
while(RUN == 1):
		item = None
		try:
			item = RQ.get(timeout=1)
		except KeyboardInterrupt:
			log("user break")
			break
		except XXX:
			item = None
		except:
			#some exception
		if(item != None):
			print(item)
Now I need to know what to put in XXX to catch the queue timeout. I have tried many things I found but none worked. Note this is just a code fragment.

Thanks
Kind regards
(Apr-22-2022, 05:43 PM)Pythocodras Wrote: [ -> ]Hello,
I have a simple script that waits for a queue with a timeout. I would like to catch that specific exception but cant find the correct one.
import multiprocessing as mp
RQ = mp.Queue()
while(RUN == 1):
		item = None
		try:
			item = RQ.get(timeout=1)
		except KeyboardInterrupt:
			log("user break")
			break
		except XXX:
			item = None
		except:
			#some exception
		if(item != None):
			print(item)
Now I need to know what to put in XXX to catch the queue timeout. I have tried many things I found but none worked. Note this is just a code fragment.

Thanks
Kind regards

Just figured it out in case anyone also needs it. You need to combine it with import queue and then catch queue.Empty.