Skip to content

Add support for loop.sock_sendto #561

Open
@difeid

Description

@difeid
  • uvloop version: 0.17.0 - 0.20.0
  • Python version: 3.11.4 - 3.12.5
  • Platform: Linux
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: Not a bug
  • Does uvloop behave differently from vanilla asyncio? How?: Yes, not implemented feature

The uvloop not implement method sock_sendto.

coroutine loop.sock_sendto(sock, data, address)
Send a datagram from sock to address. Asynchronous version of socket.sendto()

Return the number of bytes sent.
sock must be a non-blocking socket.
New in version 3.11.

The simple test case that reproduces the problem:

#!/usr/bin/env python3

import socket
import asyncio
import uvloop

uvloop.install()

async def run():
    addr = ("127.0.0.1", 1111)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setblocking(False)
    loop = asyncio.get_running_loop()
    await loop.sock_sendto(s, b'test', addr)

asyncio.run(run())

uvloop == 0.20.0 response:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "<stdin>", line 6, in run
  File "uvloop/loop.pyx", line 2629, in sock_sendto
NotImplementedError

Activity

WilliamOConnell

WilliamOConnell commented on Aug 7, 2024

@WilliamOConnell

I had a similar issue with sock_recvfrom. It took me a while to figure out what was going on because I was using Sanic and hadn't actually heard of uvloop. I got around it by disabling it in the Sanic config but it would be nice if these methods could be implemented.

difeid

difeid commented on Aug 27, 2024

@difeid
Author

Yes, sock_recvfrom is also not implemented
uvloop/loop.pyx

@cython.iterable_coroutine
async def sock_recvfrom(self, sock, bufsize):
    raise NotImplementedError

@cython.iterable_coroutine
async def sock_recvfrom_into(self, sock, buf, nbytes=0):
    raise NotImplementedError

@cython.iterable_coroutine
async def sock_sendto(self, sock, data, address):
    raise NotImplementedError
linked a pull request that will close this issue on Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @difeid@WilliamOConnell

      Issue actions

        Add support for loop.sock_sendto · Issue #561 · MagicStack/uvloop