Victor, I agree with Chetan -- each event loop has its own state and this
normally works fine -- it is a problem specific to the subprocess watcher
architecture. Maybe we can get its original author interested again?

On Mon, Aug 10, 2015 at 12:54 PM, <chetanre...@gmail.com> wrote:

> Hi Victor,
>
> If i use asyncio.sleep instead of create_subprocess_shell, it works find
> even though i have two event loops. There are no errors; the only warning i
> get is about the task taking too long (slow_callback_duration is 0.1 while
> my task takes 2 seconds so the warning is expected).
>
> Here's the program (with two event loops) that works
>
> ----------------------------------------------------
> import asyncio
> import logging
>
> async def sleepWithAsyncio(loop=None):
>     await asyncio.sleep(2, loop=loop)
>     return True
>
> def sleepWithNewLoop():
>     loop = asyncio.new_event_loop()
>     result = loop.run_until_complete(sleepWithAsyncio(loop))
>     loop.close()
>     return result
>
> async def sleepWithMainLoopAndNewLoop():
>     result = await sleepWithAsyncio()
>     print("sleep with asyncio in main loop ", result)
>     result = sleepWithNewLoop()
>     print("sleep with asyncio in new 'nested' loop ", result)
>     return result
>
> def main():
>     logging.basicConfig(level=logging.DEBUG)
>
> asyncio.get_event_loop().run_until_complete(sleepWithMainLoopAndNewLoop())
>     asyncio.get_event_loop().close()
>
> if __name__ == "__main__":
>     main()
>
> -----------------------------------------------------
>
>
> Thanks,
> Chetan
>
>
> On Monday, August 10, 2015 at 5:52:39 AM UTC-4, Victor Stinner wrote:
>>
>> To me it looks wrong to have two event loops per thread. You must get an
>> error, at least in debug mode.
>>
>> What do you want to do?
>>
>> Victor
>>
>


-- 
--Guido van Rossum (python.org/~guido)

Reply via email to