from curio import run, spawn, tcp_server
async def echo_client(client, addr):
print('Connection from', addr)
s = client.as_stream()
async for line in s:
print(line)
if __name__ == '__main__':
run(tcp_server('', 8260, echo_client))
using curio-0.4, windows 10, Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015...
works without issue.
program output:
Connection from ('127.0.0.1', 49521)
b'{"method":"@enable_push","params":{"push_name":"log"},"id":12267}\n'
b'{"method":"Symphony.Status","params":null,"id":12268}\n'
b'{"method":"Symphony.GetUnits","params":null,"id":12269}\n'
using curio-0.5, windows 10, Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015...
Connection from ('127.0.0.1', 64726)
Curio: Task Crash: _run_server.<locals>.run_client
Traceback (most recent call last):
File "C:\Program Files\Python35\lib\site-packages\curio\kernel.py", line 836, in _run
trap = current._send(current.next_value)
File "C:\Program Files\Python35\lib\site-packages\curio\network.py", line 87, in run_client
await client_connected_task(client, addr)
File "c:\Evobase2005\Main\EvoPro\PyTools\tests\sandbox.py", line 7, in echo_client
async for line in s:
TypeError: 'async for' received an invalid object from __aiter__: SocketStream
There was a change in the asynchronous iteration protocol going from Python 3.5.1 to Python 3.5.2 (and newer). You might try this on Python 3.5.2 if possible.
using test code:
using curio-0.4, windows 10, Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015... works without issue. program output:
using curio-0.5, windows 10, Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015...