Skip to content

Commit 80d5cd5

Browse files
authored
Merge pull request #4130 from hove-io/patch_all_variable_env
[Jormungandr] PATCH_WITH_GEVENT_SOCKET_ALL added
2 parents 6da0a5c + 83ac15c commit 80d5cd5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

source/jormungandr/jormungandr/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# we want to patch gevent as early as possible
4747
if app.config.get(str('PATCH_WITH_GEVENT_SOCKET'), False):
48-
init.patch_http()
48+
init.patch_http(patch_level=app.config.get(str('PATCH_WITH_GEVENT_SOCKET_LEVEL'), "socket"))
4949

5050
from jormungandr import new_relic
5151

source/jormungandr/jormungandr/default_settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@
312312
# These parameters are used to apply gevent's monkey patch
313313
# The Goal is to activate parallel calling valhalla, without the patch, parallel http and https calling may not work
314314
PATCH_WITH_GEVENT_SOCKET = bool(os.getenv('JORMUNGANDR_PATCH_WITH_GEVENT_SOCKET', True))
315+
# PATCH_WITH_GEVENT_SOCKET_LEVEL : values possibles all, thread or socket
316+
PATCH_WITH_GEVENT_SOCKET_LEVEL = os.getenv('JORMUNGANDR_PATCH_WITH_GEVENT_SOCKET_LEVEL', 'socket')
315317

316318
GREENLET_POOL_SIZE = int(os.getenv('JORMUNGANDR_GEVENT_POOL_SIZE', 10))
317319

source/jormungandr/jormungandr/init.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,26 @@ def logger(app):
5454
app.logger.setLevel('INFO')
5555

5656

57-
def patch_http():
57+
def patch_http(patch_level="socket"):
5858
logger = logging.getLogger(__name__)
5959
logger.info(
6060
"Warning! You'are patching socket with gevent, parallel http/https calling by requests is activated"
6161
)
6262

6363
from gevent import monkey
6464

65-
monkey.patch_ssl()
66-
monkey.patch_socket()
65+
logger.warning("patch_level : {}".format(patch_level))
66+
if patch_level == "all":
67+
monkey.patch_all()
68+
elif patch_level == "thread":
69+
monkey.patch_ssl()
70+
monkey.patch_socket()
71+
monkey.patch_thread()
72+
monkey.patch_selectors()
73+
else:
74+
# Socket default value
75+
monkey.patch_ssl()
76+
monkey.patch_socket()
6777

6878

6979
def street_network_backends(app):

0 commit comments

Comments
 (0)