Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Pau Freixes
Sorry a bit of topic, but I would like to figure out why older python versions, prior this commit [1], the get_event_loop is not considered deterministic does anybody know the reason behind this change? [1] https://github.com/python/cpython/commit/600a349781bfa0a8239e1cb95fac29c7c4a3302e On Fr

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Guido van Rossum
In theory it's possible to create two event loops (using new_event_loop()), then set one as the default event loop (using set_event_loop()), then run the other one (using run_forever() or run_until_complete()). To tasks running in the latter event loop, get_event_loop() would nevertheless return th

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Pau Freixes
And what about the rationale of having multiple loop instances in the same thread switching btw them. Im still trying to find out what patterns need this... Do you have an example? Btw thanks for the first explanation El 12/06/2017 17:36, "Guido van Rossum" escribió: > In theory it's possible t

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Guido van Rossum
Multiple loops in the same thread is purely theoretical -- the API allows it but there's no use case. It might be necessary if a platform has a UI-only event loop that cannot be extended to do I/O -- the only solution to do background I/O might be to alternate between two loops. (Though in that cas

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Andrew Svetlov
Unit tests at least. Running every test in own loop is crucial fro tests isolation. On Mon, Jun 12, 2017 at 7:04 PM Guido van Rossum wrote: > Multiple loops in the same thread is purely theoretical -- the API allows > it but there's no use case. It might be necessary if a platform has a > UI-onl

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Guido van Rossum
Yes, but not co-existing, I hope! On Mon, Jun 12, 2017 at 9:25 AM, Andrew Svetlov wrote: > Unit tests at least. Running every test in own loop is crucial fro tests > isolation. > > On Mon, Jun 12, 2017 at 7:04 PM Guido van Rossum wrote: > >> Multiple loops in the same thread is purely theoretic

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Andrew Svetlov
Yes, but with one exception: default event loop created on module import stage might co-exist with a loop created for test. It leads to mystic hangs, you know. Please recall code like: class A: mongodb = motor.motor_asyncio.AsyncIOMotorClient() On Mon, Jun 12, 2017 at 7:37 PM Guido va

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Ben Darnell
In Tornado this comes up sometimes in initialization scenarios: def main(): # Since main is synchronous, we need a synchronous HTTP client with tornado.httpclient.HTTPClient() as client: # HTTPClient creates its own event loop and runs it behind the scenes.

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Guido van Rossum
Honestly I think we're in agreement. There's never a use for one loop running while another is the default. There are some rare use cases for multiple loops running but before the mentioned commit it was up to the app to ensure to switch the default loop when running a loop. The commit took the abi

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Andrew Svetlov
Agree in general but current asyncio still may shoot your leg. The solution (at least for my unittest example) might be in adding top level functions for running asyncio code (asyncio.run() and asyncio.run_forever() as Yury Selivanov proposed in https://github.com/python/asyncio/pull/465) After thi

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread Guido van Rossum
I think we're getting way beyond the rationale Pau Freixes requested... On Mon, Jun 12, 2017 at 12:05 PM, Andrew Svetlov wrote: > Agree in general but current asyncio still may shoot your leg. > The solution (at least for my unittest example) might be in adding top > level functions for running

Re: [Async-sig] async/sync library reusage

2017-06-12 Thread manuel miranda
So, I've been playing a bit with the information I saw in this thread (thank you all for the responses) and I got something super simple working: https://gist.github.com/argaen/056a43b083a29f76ac6e2fa97b3e08d1 What I like about this (and that's what I was aiming for) is that the user uses the same