On Mon, Jan 19, 2015 at 12:02 PM, Victor Stinner <[email protected]> wrote: > 2015-01-19 12:52 GMT+01:00 Luciano Ramalho <[email protected]>: >> In a non-trivial program, how do I know mine was the first call to >> get_event_loop? > > It doesn't matter who called it first. You may even call close() more > than once ;-)
I am sorry, but I can't reconcile that with this quote from Guido's last comment closing your bug report [1]. What am I missing? """ Well, calling close() is best practice *if you own the loop*. But the thing is that you may not own what get_event_loop() returns, and in fact in most cases where it is called you don't own it. """ [1] http://bugs.python.org/msg205062 > In an application, I hope that you know when the application is going to exit! In a GUI application you may know it's about to exit but you don't own the event loop. Victor, I think your bug report is right on: the event loop should be useable as context manager, what is missing is a method in the AbstractEventLoopPolicy interface to make it possible to implement a suitable __exit__. If AbstractEventLoopPolicy.get_event_loop() exists to accommodate environments providing event loops in their different ways, then the AbstractEventLoopPolicy interface should have a function that could be safely called by anyone to notify the environment you don't need the loop anymore. Such a function -- maybe release_event_loop() -- could be called by a BaseEventLoop.release() instance method and by a BaseEventLoop.__exit__ method. I'd appreciate some feedback to this idea, or clarifications if I am getting something wrong. Cheers, Luciano -- Luciano Ramalho Twitter: @ramalhoorg Professor em: http://python.pro.br Twitter: @pythonprobr
