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
  try catch not working? korenron 2 849 Jan-15-2023, 01:54 PM
Last Post: korenron
  FTp timeout except korenron 2 3,596 Feb-01-2022, 06:51 AM
Last Post: korenron
  twisted: catch return from sql wardancer84 0 1,542 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,872 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 4,734 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,155 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  try catch question ,get data from main code korenron 7 3,196 Nov-03-2020, 09:28 AM
Last Post: korenron
  Multiprocessing, class, run and a Queue Object SeanInColo 0 1,552 Jul-12-2020, 05:36 PM
Last Post: SeanInColo
  task queue Valon1981 8 3,616 Jul-07-2020, 07:41 AM
Last Post: freeman
  Queue in Pygame constantin01 1 3,699 Jan-07-2020, 04:02 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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