[Tutor] signals and frame objects
Marilyn Davis
marilyn at deliberate.com
Wed Sep 15 21:31:16 CEST 2004
Oh wow. That is so easy. I thought I had to manipulate the frame
object somehow to get back to where I was. Thank you so much Kent.
Marilyn
On Wed, 15 Sep 2004, Kent Johnson wrote:
> If you return from the handler, processing will continue where it was
> interrupted. If you want to inspect the frame object in your handler, some
> information about it is available here:
> http://docs.python.org/ref/types.html#l2h-142
>
> For example, running this program in IDLE on MacOSX:
> #############################
> import signal
>
> done = 0
> def handler(signum, frame):
> print frame
> print dir(frame)
> print 'Signal handler called with signal', signum
> global done
> done = 1
>
> # Set the signal handler and an alarm
> signal.signal(signal.SIGALRM, handler)
> signal.alarm(3)
>
> print "Looping"
> while not done:
> pass
>
> print "Out of loop"
>
> signal.alarm(0) # Disable the alarm
>
> print "Done"
> ##############################3
>
> gives this output:
> >>> ================================ RESTART ================================
> >>>
> Looping
> <frame object at 0x4fd6c0>
> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
> '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
> '__setattr__', '__str__', 'f_back', 'f_builtins', 'f_code',
> 'f_exc_traceback', 'f_exc_type', 'f_exc_value', 'f_globals', 'f_lasti',
> 'f_lineno', 'f_locals', 'f_restricted', 'f_trace']
> Signal handler called with signal 14
> Out of loop
> Done
> >>>
>
> Kent
>
>
> At 09:23 AM 9/15/2004 -0700, Marilyn Davis wrote:
> >Hello Tutors,
> >
> >I'm setting a signal.alarm() and I am successful in catching it in my
> >handler function. The parameters given to me in my handler include
> >the stack frame. Is there some way I can use that stack frame to
> >continue processing?
> >
> >Thank you for any help anyone can give.
> >
> >Marilyn Davis
> >
> >--
> >
> >_______________________________________________
> >Tutor maillist - Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
More information about the Tutor
mailing list