-
-
Notifications
You must be signed in to change notification settings - Fork 219
Description
I've encountered an issue with psycopg calls blocking execution of other greenlets when running under gevent. Initially, problem manifested itself in celery worker, but during a debugging session I've reproduced it with the demonstration script from issue #4 . Here is the output of running it with psycopg[c]==3.1.8 and gevent==22.10.2 (latest version ATM):
$ python3 ./test.py
2023-03-21 16:12:32,165 start threads
2023-03-21 16:12:32,165 connecting 0
2023-03-21 16:12:32,166 connecting 1
2023-03-21 16:12:32,166 connecting 2
2023-03-21 16:12:32,178 querying 1
2023-03-21 16:12:34,183 queried 1
2023-03-21 16:12:34,184 querying 0
2023-03-21 16:12:36,191 queried 0
2023-03-21 16:12:36,194 querying 2
2023-03-21 16:12:38,205 queried 2
2023-03-21 16:12:38,206 end threads
After poking around in psycopg/waiting.py and using particular undocumented env var to set wait function to wait_select or wait_selector, I've observed expected behavior - queries were running concurrently. Choosing wait_c or unsetting the env var resulted in blocking wait. I've traced the issue back to commit 9465578 between 3.1.4 and 3.1.5 (checked on psycopg[c]==3.1.4 - no issue indeed).
I suppose that monkey-patching, that gevent does, is not working for functions from C modules. Is there anything that can be done to enable concurrent queries? What are benefits of wait_c over wait_select[or]?
Python 3.10.6 on Linux, aarch64
libpq-dev 14.7-0ubuntu0.22.04.1
libpq5:arm64 14.7-0ubuntu0.22.04.1