2

I tried to run my Flask project with gevent on Python3.7 on Raspberry Pi with gevent.monkey.patch_all() on the first line. But it ended up with this error:

Traceback (most recent call last):
   File "src/gevent/_hub_local.py", line 71, in gevent._gevent_c_hub_local.get_hub
   File "src/gevent/_hub_local.py", line 80, in gevent._gevent_c_hub_local.get_hub_noargs
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/hub.py", line 445, in __init__
     self.loop = self.loop_class(flags=loop, default=default) # pylint:disable=not-callable
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/hub.py", line 459, in loop_class
     return GEVENT_CONFIG.loop
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/_config.py", line 50, in getter
     return self.settings[setting_name].get()
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/_config.py", line 146, in get
     self.value = self.validate(self._default())
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/_config.py", line 248, in validate
     return self._import_one_of([self.shortname_map.get(x, x) for x in value])
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/_config.py", line 219, in _import_one_of
     return self._import_one(item)
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/_config.py", line 237, in _import_one
     module = importlib.import_module(module)
   File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
   File "<frozen importlib._bootstrap>", line 980, in _find_and_load
   File "<frozen importlib._bootstrap>", line 149, in __enter__
   File "<frozen importlib._bootstrap>", line 88, in acquire
   File "src/gevent/_semaphore.py", line 273, in gevent._gevent_c_semaphore.Semaphore.__enter__
   File "src/gevent/_semaphore.py", line 274, in gevent._gevent_c_semaphore.Semaphore.__enter__
   File "src/gevent/_semaphore.py", line 175, in gevent._gevent_c_semaphore.Semaphore.acquire
   File "/home/pi/server/venv/lib/python3.7/site-packages/gevent/thread.py", line 121, in acquire
     acquired = BoundedSemaphore.acquire(self, blocking, timeout)
   File "src/gevent/_semaphore.py", line 175, in gevent._gevent_c_semaphore.Semaphore.acquire
   File "src/gevent/_semaphore.py", line 200, in gevent._gevent_c_semaphore.Semaphore.acquire
 OverflowError: Python int too large to convert to C long

On my PC (Python3.8), where is everything working OK, I am getting this warning:

init.py:1: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (/usr/local/lib/python3.8/dist-packages/urllib3/util/__init__.py)', 'urllib3.util.ssl_ (/usr/local/lib/python3.8/dist-packages/urllib3/util/ssl_.py)'].

I need to have patch monkey, because when I remove it, everything else is working well, but emitted sockets from external threads are stacking and buffering and arriving to JavaScript handlers after long time.

My versions of modules:

Flask==1.1.2
Flask-SocketIO==5.0.1
python-engineio==4.0.0
python-socketio==5.04
gevent==20.12.1
gevent-websocket==0.10.1

Anyone knows, how can I solve this issue?

Thanks.

davidism
  • 121,510
  • 29
  • 395
  • 339
Foreen
  • 369
  • 2
  • 17
  • please show code with the imports also – hootnot Jan 06 '21 at 13:39
  • 1
    regarding the RPI: check if you run 32bit or 64bit: https://stackoverflow.com/questions/38314118/overflowerror-python-int-too-large-to-convert-to-c-long-on-windows-but-not-ma – hootnot Jan 06 '21 at 13:46
  • Here are my imports, it fails on the first line: import gevent.monkey; gevent.monkey.patch_all() # patch_thread() # thread=True, select=False) from werkzeug.security import generate_password_hash, check_password_hash from flask_login import LoginManager, UserMixin from flask_sqlalchemy import SQLAlchemy from flask_socketio import SocketIO from flask_babel_js import BabelJS from flask_babel import Babel from flask import Flask import platform import datetime import socket import sys import os – Foreen Jan 06 '21 at 15:16
  • Yes, you are right. On my PC I am running 64 bit and on RPi only 32 bit. That will be probably the problem! Thank you. And do you know, how can I fix the problem with MonkeyPatchWarning, which I am getting? – Foreen Jan 06 '21 at 15:21
  • Guess you need to do some googling: https://github.com/miguelgrinberg/Flask-SocketIO/issues/943, maybe you find some clues here – hootnot Jan 07 '21 at 15:00
  • 1
    I use gevent myself with Python 3.8.5 and have no issues. You have no tricky issues cause by imports from a __init__,py file ? Maybe create a fresh virtual environment and start with basic packages you need and check where it goes wrong – hootnot Jan 07 '21 at 15:35
  • do you have *python3-openssl* installed ? (see the github link) – hootnot Jan 07 '21 at 15:42
  • Thank you for your answer, package python3-openssl I had not installed. I install it, but the MonkeyPatchWarning is still there. I tried to run directly only one line of my code (only the import of gevent and monkey patch) - import gevent.monkey; gevent.monkey.patch_all() and it still leads to the same warning. – Foreen Jan 08 '21 at 15:12
  • Oh, thank you very much! You really helped me! Yes, I installed clean venv with only required modules for current project and now it is working! – Foreen Jan 08 '21 at 15:29
  • Can I have a last question? Is there any solution to run this on 32-bit system? Because I cannot install 64-bit Python to my RPi. – Foreen Jan 08 '21 at 15:32
  • 1
    https://ubuntu.com/download/raspberry-pi shows 64bit options. So, I think the shortest path is to get that done. It is easy to experiment with another SD-card – hootnot Jan 08 '21 at 18:10
  • Yes, I tried it, but it is not as fast as Raspbian. I need GNOME, too (respectively Chromium). And on Ubuntu it was really slow. So, for my purpose I ideally need Raspbian. – Foreen Jan 09 '21 at 10:57

1 Answers1

0

The problem was that I was running 32bit instead of 64bit Python3 on RPi.

Foreen
  • 369
  • 2
  • 17