[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [globus-python] keyboard interrupt?
Edinburgh perhaps for the beer?
cheers,
--keith
Jonathan P Giddy wrote:
> Quoting Keith Jackson <krjackson@lbl.gov>:
>
>
>>Yes, and I haven't figured out how to fix it yet. If anyone has any good
>>ideas, I'd buy them a beer at the next conference. :-)
>>--keith
>>
>>
>
> OK, then, this happens because the Python interpreter only allows the
> "main" thread to handle signals (and hence Ctrl-C). When a signal is
> caught, it is put in a queue, and every time round the bytecode evaluation
> loop the main thread checks for any pending signals. If it's a SIGINT, a
> KeyboardInterrupt is raised.
>
> When the main thread is waiting in a system call, it doesn't check the
> queue until the call finishes and it evaluates more bytecodes. An accept()
> of course doesn't return until a network connection occurs.
>
> Two possible solutions:
>
> 1. Put all your code in non-main threads, and create a simple main thread
> that does "while not done: time.sleep(0.2)", ensuring the thread handles
> a signal in 0.1 of a second on average.
>
> 2. Put the above timeout in a select:
> while not done:
> r = select.select([sock], [], [], 0.2)
> # any pending signals handled now
> if sock in r:
> conn, addr = sock.accept()
> ...
>
> Cheers,
> Jon.
>
>
>
>>Robert Olson wrote:
>>
>>
>>>Does anyone else see the effect where a GSISocketServer listener cannot
>>>be interrupted with the keyboard interrupt until a network request
>>>actually comes in?
>>>
>>>--bob
>>>
>>>
>
> --
> Jonathan Giddy
> Grid Technologies Co-ordinator
> The Welsh e-Science Centre
> Cardiff University
> ph +44 (0)29 2087 6998
> fax +44 (0)29 2087 4598
> J.P.Giddy@wesc.ac.uk
>
>
--
----------------------------------------------------------------
Keith R. Jackson KRJackson@lbl.gov
Grid Technology Group (510) 486-4401
Lawrence Berkeley National Laboratory http://www-itg.lbl.gov/~kjackson/