[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-22 Thread Simon Bernier St-Pierre
Changes by Simon Bernier St-Pierre : -- status: open -> closed ___ Python tracker ___

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-21 Thread Simon Bernier St-Pierre
Simon Bernier St-Pierre added the comment: I created a patch for it on the asyncio github repo. https://github.com/python/asyncio/pull/321 -- ___ Python tracker

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Martin Panter
Martin Panter added the comment: If your event loop supports it, maybe you could use add_reader() etc as a workaround (roughly based off a different function of my own; this version completely untested): async def sock_recvfrom(nonblocking_sock, *pos, loop, **kw): while True: try:

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre
Simon Bernier St-Pierre added the comment: I want to have a loop that receives data like this: socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) socket.bind(('0.0.0.0', port)) socket.setblocking(False) while True: data, addr = await loop.sock_recvfrom(sock, 4096) # process

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Guido van Rossum
Guido van Rossum added the comment: I won't make you go through the PEP process, but I do think it's a bad idea to add this. After all datagrams aren't guaranteed to arrive, so, whil I don't know what protocol you're trying to implement, I think you're probably better off writing the whole thing

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre
Simon Bernier St-Pierre added the comment: That could work. I came up with this class MyProtocol(aio.DatagramProtocol): def __init__(self, fut): self._fut = fut def datagram_received(self, data, addr): self.fut.set_result((data, addr)) fut = aio.Future()

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Guido van Rossum
Guido van Rossum added the comment: You should be able to do this by calling create_datagram_endpoint(), passing it a custom DatagramProtocol subclass whose datagram_received() stores the data in the result of a Future. You can then wait for the Future to wait for the data (assuming it ever

[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre
New submission from Simon Bernier St-Pierre: I want to receive data on a UDP socket that was bound, without blocking the event loop. I've looked through the asyncio docs, and I haven't found a way of doing that using the coroutine API (yield from/await). There is a sock_recv method on