Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process pool should be initiated once #195

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
make install
RUN rm -R ta-lib ta-lib-0.4.0-src.tar.gz

RUN pip install pylivetrader==0.5.0
RUN pip install pylivetrader==0.5.1
2 changes: 1 addition & 1 deletion pylivetrader/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION = '0.5.0'
VERSION = '0.5.1'
9 changes: 7 additions & 2 deletions pylivetrader/misc/parallel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
from multiprocessing import Pool

PROCESS_POOL = None


def _get_default_workers():
workers = os.environ.get('PYLT_NUM_WORKERS')
Expand Down Expand Up @@ -55,8 +57,11 @@ def parallelize_with_multi_process(mapfunc, workers=10):

Return: func(args_list) => list[func[arg]]
"""
global PROCESS_POOL
if not PROCESS_POOL:
PROCESS_POOL = Pool(workers)

def wrapper(args_list):
with Pool(workers) as pool:
return pool.map(mapfunc, args_list)
return PROCESS_POOL.map(mapfunc, args_list)

return wrapper