Comments (3)
I made a PR for this: #8 but I'm concerned that this is not as simple as it seems, I'm curious to know in what cases the main thread's event loop possibly be used by an asyncio
Future
/coroutine
that might be awaited by an @unsync
function.
It appears that coroutines
started in the main thread will still get executed in the event loop of the coroutine
that awaits it. I'm pretty sure that means this change is safe, but I'm going to spend some more time looking into any other ways a coroutine
/Future
from asyncio
could get executed in main thread's event loop while being awaited by an @unsync
function.
from unsync.
I expect unsync
to work in another thread with its own event loop and don't make a mess with main thread and loop. Don't know how to implement it. Any ideas?
from unsync.
It's ok that coroutine will get executed in the event loop of another coroutine that awaits it. But simple async
functions that is not marked with @unsync
decorator should not be executed in the unsync
event loop. Here is what I mean in code:
async def async_coro_returning_event_loop() -> asyncio.AbstractEventLoop:
await asyncio.sleep(0.001)
loop = asyncio.get_event_loop()
return loop
@unsync
async def unsync_coro_returning_event_loop() -> asyncio.AbstractEventLoop:
return await async_coro_returning_event_loop()
main_loop = asyncio.get_event_loop()
unsync_loop = unsync.loop
assert main_loop != unsync_loop
assert main_loop == await async_coro_returning_event_loop()
assert unsync_loop == unsync_coro_returning_event_loop().result()
It seems that #8 fixes issue -- unsync
does asyncio.set_event_loop
in its own separate thread.
from unsync.
Related Issues (20)
- Async generators HOT 2
- Defining the amount of threads in use for sync functions HOT 3
- How to handle errors and exceptions? HOT 1
- Can't Import unsync on AWS Lambda HOT 5
- Cython support
- @unsync(cpu_bound=True) Windows 10 64 error HOT 1
- Any support or alternative for `asyncio.Semaphore`? HOT 4
- Calling nested results() on futures produces InvalidStateError HOT 1
- Unsync conda-forge recipe
- Python 3.9.x compatability? HOT 6
- Decorator problem HOT 1
- process_executor.py example on Windows 7 orphans the multiprocess kernels HOT 1
- Ability to limit concurrency? HOT 4
- Leftover debug? DERP HOT 2
- Continuation with cpu_bound functions HOT 2
- CPU Bound Decorator in Wrapped Functions HOT 1
- Using @unsync decorator in Jupyter results in error HOT 1
- max_workers HOT 3
- closing old processes HOT 3
- `BrokenProcessPool` error using function with `cpu_bound=True` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unsync.