How to shut down a TCPServer serve_forever() loop?

Marko Rauhamaa marko at pacujo.net
Tue Nov 28 13:54:53 EST 2017


Chris Angelico <rosuav at gmail.com>:
> On Wed, Nov 29, 2017 at 5:32 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Don't you worry about my programs.
>
> Okay, but you can't claim that problems are solvable if you cheat them.

What I'm saying is that there's no particular reason why glibc couldn't
offer a solution. There *is* getaddrinfo_a(), but that's suboptimal
because it uses signals and (probably) a subsidiary thread. Instead, it
should offer a file descriptor for the application to monitor.

>> Please reread the original poster's question. It was about a blocking
>> TCP listener call that another thread couldn't interrupt.
>
> Yet a SIGINT would successfully interrupt it.

A keyboard interrupt? That your magic bullet? How does that work in
practice?

> 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>


Marko



More information about the Python-list mailing list