[Python-ideas] Re: Asyncio Future.set_result_threadsafe

2020-02-13 Thread Kyle Stanley
Oops, I forgot to start the thread in the above example for compute_something(), ``th.start()`` should go right after initializing the thread but before the try-finally block On Thu, Feb 13, 2020 at 6:15 PM Kyle Stanley wrote: > > I agree that is counter to the basic philosophy, though there

[Python-ideas] Re: Asyncio Future.set_result_threadsafe

2020-02-13 Thread Kyle Stanley
> I agree that is counter to the basic philosophy, though there are potential use cases where it may be unavoidable to use threads. It seems the best solutions when it is then are to use run_in_executor, which automatically handles the waking up of the loop. While this doesn't provide an

[Python-ideas] Re: Asyncio Future.set_result_threadsafe

2020-02-13 Thread Brianvanderburg2 via Python-ideas
I agree that is counter to the basic philosophy, though there are potential use cases where it may be unavoidable to use threads.  It seems the best solutions when it is then are to use run_in_executor, which automatically handles the waking up of the loop.  While the Queue object doesn't work

[Python-ideas] Re: Asyncio Future.set_result_threadsafe

2020-02-12 Thread Guido van Rossum
Sharing futures between threads like that goes counter to asyncio's basic philosophy (which is not to use threads :-). You already showed the solution: future._loop.call_soon_threadsafe(future.set_result, ...). If that's unacceptable for you, maybe you can wrap the future in a wrapper class that