Skip to content

Commit

Permalink
Gevent instead of multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardbinet committed Jan 16, 2017
1 parent 008781d commit 34183f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ And many more to come:
- client.requested_urls attribute if you want to see all urls requested by your client.

## TODO
- replace multiprocessing by gevent async requests

### CLEAN REPO:
- unit tests
Expand Down
8 changes: 5 additions & 3 deletions navitia_client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
This module computes API requests.
"""
from gevent import monkey
monkey.patch_all()

import functools
import os
from datetime import datetime, timedelta
Expand All @@ -9,7 +12,7 @@
import json
import requests

from multiprocessing import Pool
from gevent.pool import Pool
from navitia_client.utils import important_print
import navitia_client

Expand Down Expand Up @@ -172,13 +175,12 @@ def _get_multipage(self, url, page_limit=10, count=100, extra_params=None, verbo

# Query other pages, multiprocessing
pages = range(1, page_limit)
pool = Pool(processes=30)
pool = Pool(30)
n = len(pages)
all_parameters = zip([self] * n, [url] * n,
pages, [count] * n, [extra_params or {}] * n, [verbose] * n)

list_tuples = pool.map(unwrap_self, all_parameters)
pool.close()
pool.join()
# Add results to initial results (first page)
responses.update(dict(list_tuples).items())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name='navitia_client',
packages=['navitia_client'],
version='0.5',
version='0.6.1',
description='Navitia client for python',
author='Leonard Binet',
author_email='[email protected]',
Expand Down

0 comments on commit 34183f9

Please sign in to comment.