python-socketio: Error while running the server example from the docs
I’m trying to run this example which is in the docs here
import eventlet
import socketio
sio = socketio.Server()
app = socketio.WSGIApp(sio, static_files={
'/': {'content_type': 'text/html', 'filename': 'index.html'}
})
@sio.event
def connect(sid, environ):
print('connect ', sid)
@sio.event
def my_message(sid, data):
print('message ', data)
@sio.event
def disconnect(sid):
print('disconnect ', sid)
if __name__ == '__main__':
eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
But as soon as I execute it I get this error
(15262) wsgi starting up on http://0.0.0.0:5000
(15262) wsgi exited, is_accepting=True
Traceback (most recent call last):
File "the_path_in_my_pc/__init__.py", line 70, in <module>
eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/wsgi.py", line 990, in server
client_socket, client_addr = sock.accept()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/greenio/base.py", line 230, in accept
self._trampoline(fd, read=True, timeout=self.gettimeout(), timeout_exc=_timeout_exc)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/greenio/base.py", line 208, in _trampoline
return trampoline(fd, read=read, write=write, timeout=timeout,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/hubs/__init__.py", line 155, in trampoline
listener = hub.add(hub.READ, fileno, current.switch, current.throw, mark_as_closed)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/hubs/kqueue.py", line 53, in add
self._control([event], 0, 0)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eventlet/hubs/kqueue.py", line 39, in _control
return self.kqueue.control(events, max_events, timeout)
TypeError: changelist must be an iterable of select.kevent objects
What may be the cause?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 17 (5 by maintainers)
I realize this issue is stale, however since this is an edge issue - and this is the first result on Google while researching, here’s how I was able to work around the issue.
Only applicable for 3.9.x from what I’ve seen
uvloop(pip install uvloop)import uvloopat the beginning of your code.uvloop.install()This should stop it from giving this issue.
Hope this helps!
@miguelgrinberg only at macos with python3.9
Also hijacking this for other Googlers: if you’re encountering this issue outside of, or without even using asyncio/the event loop, the weird error can be sidestepped by using a different selector strategy.
Just throw this somewhere it will be run early on:
selector.KqueueSelectoris the default on OSX, as it’s the most performant set of syscalls to implement file descriptor selection on OSX. But since it ain’t working at all on Python 3.9, dropping down to a less performant but working selector seems like a good trade-off.I don’t know yet. I also noticed it in my unit tests. It happens only on Python 3.9 on Mac, and I do not believe it is related to this package, but I need to investigate and see if others are seeing this error as well.
Ok, for the moment I’ll use python 3.7 then.