How to shut down a TCPServer serve_forever() loop?

Marko Rauhamaa marko at pacujo.net
Tue Nov 28 07:52:20 EST 2017


Chris Angelico <rosuav at gmail.com>:

> On Tue, Nov 28, 2017 at 5:04 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Seems to be one of the fundamental multithreading issues: each thread
>> is blocked on precisely one event. Asyncio is more flexible: you can
>> multiplex on a number of events.
>
> Not really, no. Unless select() counts as "precisely one event", of
> course.

Select() counts as asyncio.

> That's the normal way for a thread to block on multiple events on a
> Unix system. Windows has its own approximate equivalent.
>
> Surprise, surprise, that's also how event loops often implemented.
> Including ones used in packages like asyncio.

The original poster's problem seems to be caused by blocking APIs that
cannot be multiplexed using select(). A good many Python facilities are
the same way.

Such blocknoxious APIs are at the core of the multithreading programming
paradigm.


Marko



More information about the Python-list mailing list