On Mon, Jan 19, 2015 at 4:56 AM, Victor Stinner
<victor.stin...@gmail.com> wrote:
> Event loops must be closed. The first call to get_event_loop() creates an
> event loop which must be closed when you are done.

In a non-trivial program, how do I know mine was the first call to
get_event_loop?

Even a trivial program running in iPython Notebook under Qt will get
an event loop that already existed, and that it should close.

> If you run python with -Wd, you should see a warning because a pair of
> sockets are not closed. Sockets are owned by the event loop.
>
> I opened a issue to emit a ResourceWarning if an event loop (and transports)
> are not explicitly closed:
> http://bugs.python.org/issue23243

OK, but if I see such a warning and dont't have the information to do
the right thing I will be frustrated.

To determine whether I must close the event loop, I need to know
whether I started the event loop when I called get_event_loop(), or
whether I got a preexisting event loop from the runtime environment.
Is there an API that tells me that?

Even better: the BaseEventLoop could have another method, perhaps
named release(), which lets the user say he won't use the event loop
any more, delegating the decision to actually close() the loop to the
same infrastructure level that makes the decision to create a new loop
or give me an existing one when I call get_event_loop.

What do you think?

Best,



-- 
Luciano Ramalho
Twitter: @ramalhoorg

Professor em: http://python.pro.br
Twitter: @pythonprobr

Reply via email to