Interrupt Python C API

googler.1.webmaster at spamgourmet.com googler.1.webmaster at spamgourmet.com
Thu Apr 16 12:54:37 CEST 2009


On 16 Apr., 11:08, Piet van Oostrum <p... at cs.uu.nl> wrote:
> >>>>> googler.1.webmas... at spamgourmet.com (g1w) wrote:
> >g1w> hi, yes, thats true, Alan Touring told us, so it would be nice to let
> >g1w> the user abort it.
> >g1w> Is there a chance for windows, too?
>
> I don't know. I have no access to Python on Windows. Maybe there is
> setitimer support on Windows. Or maybe you can use the threading.Timer
> object, like this:
>
> import signal, os
> import threading
>
> signalcode = signal.SIGALRM # on Windows, choose one that exists there.
>
> class AlarmError(Exception):
>     pass
>
> def interrupt():
>     os.kill(os.getpid(), signalcode)
>
> def execute(command, timeout):
>     threading.Timer(timeout, interrupt).start()
>     try:
>         exec(command)
>     except AlarmError, e:
>         print e
>         print 'Aborted "%s"' % (command,)
>     print "continue work"
>
> print "The everlasting command"
> execute("while 1: pass", 10)
> print "The End"
>
> --
> Piet van Oostrum <p... at cs.uu.nl>
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p... at vanoostrum.org

thx, i will check... :) merci



More information about the Python-list mailing list