A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/331805.html below:

Exception raised but in wrong thread?

Exception raised but in wrong thread?Krzysztof Nowak pegazik at gmail.com
Mon Sep 19 16:16:49 EDT 2005
Hello. I hope you didn't receive that email before. I post this
question once but there was some error.

I have problem and I'm looking for help. Probably there is some quite
easy solution, but I can't see it.

I'm trying to perform some action that have to be timeout safe. So here
is the structure of my program:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def TimeoutHandler():
  print '!'
  raise Exception

class Active:
  def Action:
  timer = Timer(1, TimeoutHandler)
  print '1'
  timer.start()
  try:
      print '2'
      time.sleep(20)
      print '3'
  except:
      print '4'
  else:
      print '5'
  timer.cancel()
  print '6'

active = Active()
active.Action()

///////////////////////////////////////////
The output is:
12!356

My question is, why exception is not raised correctly? Could be the
reason that (probably) timer is another thread and there is no
exception in the main thread? How to solve this problem? [My timeout
should be smaller than one second so I can't use signal.alarm()]

Thanks for your reply,
Krzysztof Nowak
More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4