Comments (8)
If I run the example on Linux it fails with ImportError: The Vector API has not been loaded
. Not sure what dependencies are needed but it looks like they're Windows-specific.
Perhaps try the SelectorEventLoop instead of proactor.
Do you use the latest version of nest_asyncio?
from nest_asyncio.
Yep, Vector is specific interface only available on Windows.
I am on latest (v1.4.3).
With regards to this:
Perhaps try the SelectorEventLoop instead of proactor.
I tried the following and it seems to work (at least for the above code):
if __name__ == "__main__":
selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
import nest_asyncio
nest_asyncio.apply(loop)
loop.run_until_complete(main())
Is this what you meant? This seems to fix the issue for the code above but I will need to test more on the other code to ensure the part that needs the re-entrant asyncio still works.
Can you explain what this change does exactly?
from nest_asyncio.
Did some testing and I think using SelectorEventLoop
works even in the nested asyncio loop cases.
But I would like to understand if nest_asyncio should work in this case using the Windows ProactorEventLoop
?
from nest_asyncio.
It should work with the ProactorEventLoop
as well, but that loop is much more complex and I have little experience with the implementation.
The example has a dependency on running some special hardware interface, making it impossible for me to reproduce the problem. If you have a test case that runs as-is and shows a hanging ProactorEventLoop
that would be appreciated. Otherwise it will not really be possible to solve this.
from nest_asyncio.
I think the following should show the issue on Windows without need of any hardware. As is, the infinite()
will print. If you change useProactor = False
to True
you never get any print out even after the sleep (so slightly different to what I saw with real hardware but hopefully same root cause).
The project I am using for this is https://github.com/christiansandberg/aioisotp. Not sure if it is something to do with how that is implemented as I only see this issue when using that library.
import asyncio
import aioisotp
import selectors
async def infinite(rdr):
while True:
payload = await rdr.read(4095)
print("inf_rdr:", payload)
class EchoServer(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
def data_received(self, data):
# Echo back the same data
self.transport.write(data)
async def main():
network = aioisotp.ISOTPNetwork('vcan0',
interface='virtual',
receive_own_messages=True)
with network.open():
# A server that uses a protocol
transport, protocol = await network.create_connection(
EchoServer, 0x1CDADCF9, 0x1CDAF9DC)
# A client that uses streams
reader, writer = await network.open_connection(
0x1CDAF9DC, 0x1CDADCF9)
asyncio.create_task(infinite(reader))
writer.write(b'Hello world!')
await asyncio.sleep(6.5)
useProactor = False
if useProactor:
loop = asyncio.get_event_loop()
else:
selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
import nest_asyncio
nest_asyncio.apply(loop)
loop.run_until_complete(main())
from nest_asyncio.
Thank you very much for the updated test case. I can reproduce the issue and know now how to fix it.
from nest_asyncio.
The fix is released in v1.5.0.
from nest_asyncio.
Thanks. Tested the fix and it seems to working nicely!
from nest_asyncio.
Related Issues (20)
- 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?
- After `apply()` and `asyncio.run()`, Jupyter kernel cannot execute any code HOT 7
- Collision with AsyncIO HOT 1
- `nest_asyncio` breaks `discord.py`
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.