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