It is an intentional part of the design that all interaction with an event loop must be done from the thread owning that event loop, with the exception of call_soon_threadsafe().
On Tue, Feb 4, 2014 at 3:13 AM, Victor Stinner <[email protected]>wrote: > Hi, > > I want to run asyncio event loop in its own thread, and schedule tasks > from the main thread (or a different thread). The problem is that > asyncio.async() is not "thread-safe": it doesn't wake-up the event > loop thread. > > A workaround is to use: loop.call_soon_threadsafe(asyncio.async, ..., > loop=loop). > > Is it a bug or is the workaround the right solution? > > For your information, my question is for an event loop for the Olso > Messaging project, a component of OpenStack. See my work-in-progress > patchset: > https://review.openstack.org/#/c/70948 > > I also plan to use greenio to reuse greenlet event loop, so tasks > executed by asyncio will run in the main thread. But at least for my > tests, I would like to use a separated asyncio event loop running in a > dedicated thread. > > Victor > -- --Guido van Rossum (python.org/~guido)
