Giter VIP home page Giter VIP logo

Comments (8)

erdewit avatar erdewit commented on May 19, 2024

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.

dpatel20 avatar dpatel20 commented on May 19, 2024

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.

dpatel20 avatar dpatel20 commented on May 19, 2024

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.

erdewit avatar erdewit commented on May 19, 2024

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.

dpatel20 avatar dpatel20 commented on May 19, 2024

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.

erdewit avatar erdewit commented on May 19, 2024

Thank you very much for the updated test case. I can reproduce the issue and know now how to fix it.

from nest_asyncio.

erdewit avatar erdewit commented on May 19, 2024

The fix is released in v1.5.0.

from nest_asyncio.

dpatel20 avatar dpatel20 commented on May 19, 2024

Thanks. Tested the fix and it seems to working nicely!

from nest_asyncio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.