on master help sign in
[enh] gevent/grequests changed to the built-in threading lib
commitd959cb1c059008984554c129cb6e17b6c5394bfc authorAdam Tauber <asciimoo@gmail.com> dateFri 5 Dec 2014, 19:24 (12 years ago) parentb1b0b82
5 files changed+20−23
requirements.txt+1−1 searx/search.py+18−5 searx/webapp.py−4 setup.py+1−1 versions.cfg−12
requirements.txt+1−1
@@ -1,6 +1,6 @@
11flask
22flask-babel
3−grequests
3+requests
44lxml
55pyyaml
66python-dateutil
searx/search.py+18−5
@@ -15,7 +15,8 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1515(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
1616'''
1717
18−import grequests
18+import requests as requests_lib
19+import threading
1920import re
2021from itertools import izip_longest, chain
2122from datetime import datetime
@@ -32,6 +33,18 @@ from searx.query import Query
3233number_of_searches = 0
3334
3435
36+def threaded_requests(requests):
37+ for fn, url, request_args in requests:
38+ th = threading.Thread(
39+ target=fn, args=(url,), kwargs=request_args, name=url,
40+ )
41+ th.start()
42+
43+ for th in threading.enumerate():
44+ if th.name.startswith('http'):
45+ th.join()
46+
47+
3548# get default reqest parameter
3649def default_request_params():
3750 return {
@@ -471,9 +484,9 @@ class Search(object):
471484
472485 # specific type of request (GET or POST)
473486 if request_params['method'] == 'GET':
474− req = grequests.get
487+ req = requests_lib.get
475488 else:
476− req = grequests.post
489+ req = requests_lib.post
477490 request_args['data'] = request_params['data']
478491
479492 # ignoring empty urls
@@ -481,10 +494,10 @@ class Search(object):
481494 continue
482495
483496 # append request to list
484− requests.append(req(request_params['url'], **request_args))
497+ requests.append((req, request_params['url'], request_args))
485498
486499 # send all search-request
487− grequests.map(requests)
500+ threaded_requests(requests)
488501
489502 # update engine-specific stats
490503 for engine_name, engine_results in results.items():
searx/webapp.py−4
@@ -17,10 +17,6 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1717(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
1818'''
1919
20−from gevent import monkey
21−monkey.patch_all()
22−
23−
2420if __name__ == '__main__':
2521 from sys import path
2622 from os.path import realpath, dirname
setup.py+1−1
@@ -41,7 +41,7 @@ setup(
4141 install_requires=[
4242 'flask',
4343 'flask-babel',
44− 'grequests',
44+ 'requests',
4545 'lxml',
4646 'pyyaml',
4747 'setuptools',
versions.cfg−12
@@ -36,18 +36,6 @@ zc.recipe.testrunner = 2.0.0
3636# WebTest==2.0.11
3737beautifulsoup4 = 4.3.2
3838
39−# Required by:
40−# grequests==0.2.0
41−gevent = 1.0
42−
43−# Required by:
44−# gevent==1.0
45−greenlet = 0.4.2
46−
47−# Required by:
48−# searx==0.1
49−grequests = 0.2.0
50−
5139# Required by:
5240# robotframework-httplibrary==0.4.2
5341jsonpatch = 1.3