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

when max_threads=1, do not create a thread pool #16

Merged
merged 1 commit into from Jan 15, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions esgprep/drs/context.py
Expand Up @@ -48,6 +48,7 @@ def __init__(self, args):
if args.set_key:
self.set_keys = dict(args.set_key)
self.threads = args.max_threads
self.use_pool = (self.threads > 1)
self.project = args.project
self.action = args.action
if args.copy:
Expand Down Expand Up @@ -108,7 +109,8 @@ def __enter__(self):
# And exclude hidden files
self.sources.FileFilter[uuid()] = ('^\..*$', True)
# Init threads pool
self.pool = ThreadPool(int(self.threads))
if self.use_pool:
self.pool = ThreadPool(int(self.threads))
return self

def _check_existing_commands_file(self):
Expand All @@ -126,8 +128,9 @@ def _check_existing_commands_file(self):

def __exit__(self, *exc):
# Close threads pool
self.pool.close()
self.pool.join()
if self.use_pool:
self.pool.close()
self.pool.join()
# Decline outputs depending on the scan results
# Raise errors when one or several files have been skipped or failed
# Default is sys.exit(0)
Expand Down
6 changes: 5 additions & 1 deletion esgprep/drs/main.py
Expand Up @@ -8,6 +8,7 @@
"""

import logging
import itertools

from ESGConfigParser.custom_exceptions import NoConfigOption

Expand Down Expand Up @@ -191,7 +192,10 @@ def run(args):
logging.warning(msg)
else:
nfiles = len(ctx.sources)
processes = ctx.pool.imap(process, ctx.sources)
if ctx.use_pool:
processes = ctx.pool.imap(process, ctx.sources)
else:
processes = itertools.imap(process, ctx.sources)
if ctx.pbar:
processes = as_pbar(processes, desc='Scanning incoming files', units='files', total=nfiles)
# Process supplied files
Expand Down
9 changes: 6 additions & 3 deletions esgprep/mapfile/context.py
Expand Up @@ -44,6 +44,7 @@ def __init__(self, args):
self.notes_url = args.tech_notes_url
self.no_version = args.no_version
self.threads = args.max_threads
self.use_pool = (self.threads > 1)
self.dataset = args.dataset
if not args.no_cleanup:
self.clean()
Expand Down Expand Up @@ -109,13 +110,15 @@ def __enter__(self):
# If --latest-symlink, --version is set to "latest"
self.sources.PathFilter['version_filter'] = '/{}'.format(self.version)
# Init threads pool
self.pool = ThreadPool(int(self.threads))
if self.use_pool:
self.pool = ThreadPool(int(self.threads))
return self

def __exit__(self, *exc):
# Close threads pool
self.pool.close()
self.pool.join()
if self.use_pool:
self.pool.close()
self.pool.join()
# Decline outputs depending on the scan results
# Raise errors when one or several files have been skipped or failed
# Default is sys.exit(0)
Expand Down
6 changes: 5 additions & 1 deletion esgprep/mapfile/main.py
Expand Up @@ -11,6 +11,7 @@
import os
import re
from datetime import datetime
import itertools

from ESGConfigParser import interpolate
from lockfile import LockFile
Expand Down Expand Up @@ -186,7 +187,10 @@ def run(args):
with ProcessingContext(args) as ctx:
logging.info('==> Scan started')
nfiles = len(ctx.sources)
processes = ctx.pool.imap(process, ctx.sources)
if ctx.use_pool:
processes = ctx.pool.imap(process, ctx.sources)
else:
processes = itertools.imap(process, ctx.sources)
if ctx.pbar:
processes = as_pbar(processes, desc='Mapfile(s) generation', units='files', total=nfiles)
# Process supplied files
Expand Down