Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio.start_server relies on usocket, which is not available for circuitpython #62

Closed
robogame-dev opened this issue Dec 6, 2023 · 1 comment

Comments

@robogame-dev
Copy link

robogame-dev commented Dec 6, 2023

asyncio.start_server does not start because there is no usocket.

If anyone has a workaround for running a TCP server without polling or blocking please lmk - in the meantime it's possible to poll a non-blocking TCP socket with socketpool, but obviously without the benefits of asyncio for performance.

Minimal reproduction code - be sure to update with your specific WiFi info below:

import asyncio
import wifi


wificreds = ["your_ssidname", "your_password"]

while wifi.radio.ipv4_address is None:
    found_networks = wifi.radio.start_scanning_networks()
    for network in found_networks:
        if network.ssid == wificreds[0]:
            wifi.radio.stop_scanning_networks()
            wifi.radio.connect(*wificreds)
    if wifi.radio.ipv4_address is not None:
        break
print("connected to wifi")


async def run_server():
    await asyncio.start_server(connection_callback, wifi.radio.ipv4_address, 8747)


def connection_callback(reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
    print("incoming connection")


asyncio.run(run_server())

The output of running that code on the latest CircuitPython 8:

code.py output:
connected to wifi
Traceback (most recent call last):
File "code.py", line 26, in
File "asyncio/core.py", line 312, in run
File "asyncio/core.py", line 271, in run_until_complete
File "asyncio/core.py", line 256, in run_until_complete
File "code.py", line 19, in run_server
File "asyncio/stream.py", line 231, in start_server
ImportError: no module named 'usocket'

Code done running.

@imnotjames
Copy link
Contributor

I think this is a duplicate of #35

@dhalbert dhalbert closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants