module signal

Klaus Neuner klaus_neuner82 at yahoo.de
Wed Oct 27 04:10:36 EDT 2004


> to see that you didn't import the re module which raises a NameError.

O.k. Sorry for that. Sometimes one doesn't see the most obvious things.

So I should reformulate my problem as follows:

Why does (2) not work (though (1) does)?

# (1)

import sys, signal


class Timeout(Exception): 
    pass

def alarm_handler(signum, frame):
    raise Timeout

try:
    signal.signal(signal.SIGALRM, alarm_handler)
    signal.alarm(3) 
    n = 0
    while 1:
        print n
        n = n+1
except Timeout:
    print "Time over."

#############################################################

# (2)

import sys, signal, re

class Timeout(Exception): 
    pass

def alarm_handler(signum, frame):
    raise Timeout

try:
    signal.signal(signal.SIGALRM, alarm_handler)
    signal.alarm(3) 
    re.search("a(((.)*c)*d)*e", "abcdf"*20)
except Timeout:
    print "Time over."



More information about the Python-list mailing list