Python Forum
Multiprocessing queue catch get timeout
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing queue catch get timeout
#1
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
Reply
#2
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regex to catch what user has put in text box robertkwild 26 5,225 Jun-26-2024, 01:06 PM
Last Post: AdamHensley
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 5,382 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  try catch not working? korenron 2 1,586 Jan-15-2023, 01:54 PM
Last Post: korenron
  TimeOut a function in a class ? Armandito 1 2,496 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  FTp timeout except korenron 2 5,375 Feb-01-2022, 06:51 AM
Last Post: korenron
  twisted: catch return from sql wardancer84 0 1,930 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  printing contents of Jar on timeout Rakshan 1 2,300 Jul-30-2021, 07:48 AM
Last Post: buran
  how to catch schema error? maiya 0 2,591 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 7,136 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,895 Jul-05-2021, 11:26 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020