Comments (8)
At the same time, I don't think his argument:
I understand this will make your code slightly less elegant in some cases, but I think in the end it is for the best if you are required to define an explicit method (declared to be a coroutine)
really applies to the issue we are faced with. It is not a matter of making some code less elegant, but we have no other choice than using nest-asyncio or running another event loop in another thread (or using something like unasync), and none of them are ideal.
Also, his answer is from 2014, maybe core devs would be more inclined to reconsider the issue today?
from nest_asyncio.
There is the original discussion thread here, where the explicit decision is made to not allow nesting. The main objection by GvR is
very hard to debug problems that appeared as very infrequent and hard to predict stack overflows
This is a valid concern and care should be taking to not to exceed the recursion limit (1000 by default). When the recursion does get too deep, the long stack trace makes it very obvious what is happening though.
from nest_asyncio.
Maybe some people are changing their minds about this now: https://bugs.python.org/issue22239#msg398257
from nest_asyncio.
I think nest asyncio breaks a fundamental assumption that in if you don't await
, you cannot task switch. Now an await
can hide behind a sync call, making it behave similar as multithreaded code (a task switch can occur at 'any' moment). So, I really appreciate this project, but it should be used with caution.
from nest_asyncio.
Good point, although with nest-asyncio asyncio.run(coro)
could almost be replaced with await coro
, with the particularity that await
can now be used even if the function is not async
.
It's really in that particular case (the function where asyncio.run
is called) that task switching can happen with nest-asyncio, while it cannot without it. But yes it makes it hard to say by just looking if the function is async
.
from nest_asyncio.
I went ahead an opened python/cpython#93338. I hope you don't mind @erdewit, and of course if the PR is accepted you should be the author of it.
from nest_asyncio.
That's a great idea @davidbrochart. I think if the asyncio authors do want nesting then it might be easier for them to modify their own code then it is to copy the (simplified) nest_asyncio code over. Probably they'll also want a flag like asyncio.allow_nesting
that needs to be explicitly set first by the user, and if not set will keep the current behavior.
from nest_asyncio.
I think if the asyncio authors do want nesting then it might be easier for them to modify their own code then it is to copy the (simplified) nest_asyncio code over.
Yes, also the equivalent changes would need to be made in the C implementation.
Probably they'll also want a flag like asyncio.allow_nesting that needs to be explicitly set first by the user, and if not set will keep the current behavior.
I agree, although it seems difficult to handle the case where two libraries want different behaviors (one wants nesting, the other not).
from nest_asyncio.
Related Issues (20)
- Create new event loop if there isn't one running HOT 6
- Can't patch loop of type <class 'NoneType'> HOT 2
- nest_asyncio broke something in nbclient HOT 6
- 1.5.2 and 1.5.3 broke some current_task detection HOT 2
- 1.5.1-1.5.4 is breaking vaex due to #61 HOT 3
- nested tasks causing deadlock? HOT 1
- Request stuck in ProcessPoolExecutor HOT 4
- feature request: unapply HOT 1
- DeprecationWarning on Python 3.10
- RuntimeError: cannot enter context: <_contextvars.Context object at %> is already entered HOT 1
- ThreadPoolExecutor issue HOT 8
- Release tag for v1.5.6 HOT 1
- Execution of Unit Tests Dead Locked After Upgrade to Python 3.10.7 HOT 3
- Lost Logs HOT 1
- nest_ayncio breaks tests under Python 3.10.9 HOT 2
- nest_asyncio.apply not working unless entire asyncio package is imported HOT 1
- strange hanging behavior with `nest_asyncio` when used in combination with `concurrent.futures `ProcessPoolExecutor` HOT 3
- RFE: is it possible to start making github releases?🤔 HOT 2
- Nested asyncio.run is parallel on first call but serial on second HOT 1
- How to share websocket context in quart?
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 nest_asyncio.