Skip to content Skip to sidebar Skip to footer

Strange Problems When Using Requests And Multiprocessing

Please check this python code: #!/usr/bin/env python import requests import multiprocessing from time import sleep, time from requests import async def do_req(): r = requests.

Solution 1:

Requests async module uses gevent. If you look at the source code of gevent you will see that it monkey patches many of Python's standard library functions, including sleep:

request.async module during import executes:

from gevent import monkey as curious_george
    # Monkey-patch.
    curious_george.patch_all(thread=False, select=False)

Looking at the monkey.py module of gevent you can see:

https://bitbucket.org/denis/gevent/src/f838056c793d/gevent/monkey.py#cl-128

defpatch_time():
    """Replace :func:`time.sleep` with :func:`gevent.sleep`."""from gevent.hub import sleep
    import time
    patch_item(time, 'sleep', sleep)

Take a look at the code from the gevent's repository for details.

Post a Comment for "Strange Problems When Using Requests And Multiprocessing"