FAQ
Hello.

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 = Actice()

///////////////////////////////////////////
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

Search Discussions

  • Krzysztof Nowak at Sep 20, 2005 at 11:48 am
    Hello all python experts.

    I have problem and I ask you 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
  • Piet van Oostrum at Sep 20, 2005 at 1:08 pm
    Please don't post the same question twice with different subjects.
    --
    Piet van Oostrum <piet at cs.uu.nl>
    URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
    Private email: piet at vanoostrum.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 19, '05 at 6:44p
activeSep 20, '05 at 1:08p
posts3
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase