How to shut down a TCPServer serve_forever() loop?

Marko Rauhamaa marko at pacujo.net
Tue Nov 28 12:22:35 EST 2017


Chris Angelico <rosuav at gmail.com>:

> On Tue, Nov 28, 2017 at 11:52 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> 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.
>
> Some things are fundamentally not multiplexable, at the lower levels.

Said function is not. Neither are, say, database methods or web
operations. Yet, they are commonly implemented in a blocking fashion.

> (On Linux, and I believe most other Unix-like operating systems,
> there's no non-blocking way to open a file, nor to gethostbyname.)

The file access problem is a fundamental glitch in Linux, but
gethostbyname() is just a silly POSIX API.

> How do you propose to solve those in Python?

I have solved the gethostbyname() problem by implementing the DNS
protocol myself (in Python).

The file access issue is philosophically somewhat deep; Linux
essentially treats files as memory and vice versa. If it became an
issue, I'd have to launch a file server process.

> I don't understand why you keep insisting that asyncio and threads are
> somehow incompatible,

Where did I say that?


Marko



More information about the Python-list mailing list