How to shut down a TCPServer serve_forever() loop?

Ian Kelly ian.g.kelly at gmail.com
Tue Nov 28 14:04:10 EST 2017


On Tue, Nov 28, 2017 at 11:54 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>> Would the OP have been trivially able to send a signal to the
>> process? Yes.
>
>    Python signal handlers are always executed in the main Python thread,
>    even if the signal was received in another thread. This means that
>    signals can’t be used as a means of inter-thread communication.
>
>    <URL: https://docs.python.org/3/library/signal.html#signals-and-threads>

Being received in the other thread, it would still interrupt the
system call however, wouldn't it? Quoting from the doc:

"However, if the target thread is executing the Python interpreter,
the Python signal handlers will be executed by the main thread.
Therefore, the only point of sending a signal to a particular Python
thread would be to force a running system call to fail with
InterruptedError."



More information about the Python-list mailing list