python-socketio: Invalid async_mode specified
hello! Everything was OK when I run my python file, but it raised error run after be packed with pyinstaller:
Traceback (most recent call last):
File "ems\core\task.py", line 67, in add
File "ems\ems_socket_service.py", line 26, in __init__
File "site-packages\socketio\server.py", line 72, in __init__
File "site-packages\engineio\server.py", line 100, in __init__
ValueError: Invalid async_mode specified
the code :self.socketio = socketio.Server(async_mode='gevent')
I tried self.socketio = socketio.Server(), it’s also useless, and i have installed gevent.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 8
- Comments: 45 (9 by maintainers)
just importing gevent from engineio.async_drivers worked for me.
from engineio.async_drivers import geventIt works!!! I add ‘engineio.async_gevent’ to hiddenimports in spec file. very, very grateful for your help!! lol hahahahaha
I use
eventlet. None of the above solved my problem. Finally I got it run by these 3 steps:Modify
app.specfile:Modify
app.pyfileAdd these lines at file head, it’s useless to the python file, but it’s necessary for pyinstaller packing.
Running
pyinstallerDo NOT run
pyinstaller app.py, it will overwriteapp.spec.@Popkultur You need to ensure
engineio.async_eventletis included in the installer package.@miguelgrinberg Perfect. All I had to do was add
from engineio import async_threadingto the top of my script file to trick PyInstaller into pulling it, and that did the trick. Thanks so much!It appears you now need
‘engineio.async_drivers.eventlet’ not ‘engineio.async_eventlet’
in hidden imports using the below version:
python-engineio 3.3.0 python-socketio 3.1.2 eventlet 0.24.1
Right! If you have to use multi-threading mode like me, you can add line as below and pyinstall it:
and also force it to use threading mode when create it:
@crobertsbmw make sure the
engineio/async_threading.pymodule is also imported, so that pyinstaller pulls it, along with all of its dependencies.Maybe the solution is just as simple as importing that module like this:
from engineio.async_drivers import geventhttps://stackoverflow.com/a/55642042/8667243
pip install eventletdid the trick for meI couldn’t get around all the errors with eventlet & PyInstaller, so I uninstalled eventlet, and am trying to use the
async_mode="threading". I also putimport threadingin my main script file. When I try to run afterpyinstaller--onefile socket_app.py, I get aInvalid async_modespecified error. This comes from\site-packages\engineio\server.py__init__method. I’m baffled. Any ideas?This solved my issue, thanks!!!
Thank you very much !!!
I solved this issue by copy whole “engineio” directory to my dist/app/“engineio” For example, copy your {{python installl dir}}/Lib/site-packages/engineio to /dist/{{your app}}/engineio. then run your app
I’m still struggling with this. I’m using the following command:
My versions:
Error result:
I did not investigate this particular issue any further because I switched to using an alternate library supported by flask-socketio which worked for me with pyinstaller (gevent). However I can point you towards a solution
The key for pyinstaller support is to avoid this -> os.path.dirname(
__file__) as__file__is not defined in the expected way in a “bundled” environment. You need to do a run-time check for if you are in a bundled environment and go from there. The relevant info that should allow a good fix is in this section of the pyinstaller docs.http://pyinstaller.readthedocs.io/en/stable/runtime-information.html
It may just be that when in a “bundled” environment (sys.frozen exists) just a different path evaluation to the
eventlet.support.dnsmodule is needed (based off sys._MEIPASS and not__file__) and the sys.path temporary modification is still usableHope this helps