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

Cython Warning with Socket.IO Asyncio Client #363

Closed
Muzzamil1 opened this issue Oct 14, 2019 · 4 comments
Closed

Cython Warning with Socket.IO Asyncio Client #363

Muzzamil1 opened this issue Oct 14, 2019 · 4 comments
Labels

Comments

@Muzzamil1
Copy link

Muzzamil1 commented Oct 14, 2019

Hi @miguelgrinberg !
The versions I am using are:

  • python-engineio == 3.9.3dev
  • python-socketio == 4.3.1dev

I was trying to run the Socket.IO Asyncio client with Cython.
If I use the following program named as hello.py

import asyncio

async def say(what, when):
    await asyncio.sleep(when)
    print(what)

loop = asyncio.get_event_loop()
loop.create_task(say('first hello', 2))
loop.create_task(say('second hello', 1))

loop.run_forever()
loop.close()

and convert it into C and then in binary using Cython

$ cython hello.py --embed

$ gcc python3-config --cflags --ldflags hello.c -o hello

$ ./hello

Output

second hello
first hello

So it seems Cython works ok with Asyncio.
If I run Python socket IO client with Cython it also works (no warnings). But If I try to run it with Socket.IO Asyncio example
i.e.

import asyncio
import time
import socketio
loop = asyncio.get_event_loop()
sio = socketio.AsyncClient(reconnection=True)

@sio.event
async def connect():
print('connected to server')

@sio.event
async def disconnect():
print('disconnect !!!!!!!!!!!!!')

async def start_server():
await sio.connect('http://localhost:5000')
await sio.wait()

if name == 'main':
loop.run_until_complete(start_server())

I get this warning

/usr/local/lib/python3.5/dist-packages/socketio/asyncio_client.py:285: RuntimeWarning: coroutine 'connect' was never awaited
  await self._trigger_event('connect', namespace=namespace)

If I enable the logger I get

Attempting polling connection to http://localhost:5000/socket.io/?transport=polling&EIO=3
Polling connection accepted with {'pingTimeout': 5000, 'pingInterval': 25000,'upgrades': ['websocket'], 'sid': 'yq7YTiLos2X6kGXLAAAH'}
Engine.IO connection established
Received packet MESSAGE data 0
Attempting WebSocket upgrade to ws://localhost:5000/socket.io/?transport=websocket&EIO=3
Namespace / is connected
/usr/local/lib/python3.5/dist-packages/socketio/asyncio_client.py:285: RuntimeWarning: coroutine 'connect' was never awaited
  await self._trigger_event('connect', namespace=namespace)
WebSocket upgrade was successful
Sending packet PING data None
Received packet PONG data None

As you can see the WebSocket connection is establishing but connect event does not occur instead it gives a warning and the same thing happens for a disconnect event.
Am I missing something?

@miguelgrinberg
Copy link
Owner

This is an interesting issue. Can I ask you to run a quick test, given that you are already set up to run the test app under Cython? Can you add this to your script:

print(asyncio.iscoroutinefunction(connect))

This should print True obviously. Based on the warning that you are getting, I believe it may be possible that this is returning False under Cython, which makes python-socketio think this is a normal function (i.e. not a coroutine), and for that reason it calls the function without the await.

@Muzzamil1
Copy link
Author

Yeah, you are right. This is returning False in Cython case.

@Muzzamil1
Copy link
Author

FYI, I am running it on Raspbian OS.

@miguelgrinberg
Copy link
Owner

There is already an issue filed on the Cython project for this problem: cython/cython#2273.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants