[Python-ideas] Hooks into the IO system to intercept raw file reads/writes

Paul Moore p.f.moore at gmail.com
Tue Feb 10 15:49:09 CET 2015


On 10 February 2015 at 14:04, Victor Stinner <victor.stinner at gmail.com> wrote:
>>
>> Not many of the code samples seem to include loop.close().
>
> Which code samples? I tried to ensure that all code snippets in
> asyncio doc and all examples in Tulip repository call loop.close().

For example, in
https://docs.python.org/dev/library/asyncio-dev.html#detect-exceptions-never-consumed
the first example doesn't close the loop. Neither of the fixes given
close the loop either.

>> Maybe they should?
>
> Yes.
>
>> For example, if I have a loop.run_forever() call, should it be
>> enclosed in try: ... finally: loop.close() to ensure the loop is
>> closed?
>
> "loop.run_forever(); loop.close()" should be fine. You may use
> try/finally if you don't want to register signal handlers for
> SIGINT/SIGTERM (which is not supported on Windows yet...).

Hmm, so if I write a server and hit Ctrl-C to exit it, what happens?
That's how non-asyncio things like http.server typically let the user
quit.
Paul


More information about the Python-ideas mailing list