Skip to content

Commit

Permalink
Merge pull request #16 from alaniwi/devel
Browse files Browse the repository at this point in the history
when max_threads=1, do not create a thread pool
  • Loading branch information
glevava committed Jan 15, 2018
2 parents e1085f9 + 4aed3fa commit 1990736
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
9 changes: 6 additions & 3 deletions esgprep/drs/context.py
Expand Up @@ -49,6 +49,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 @@ -109,7 +110,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 @@ -127,8 +129,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 @@ -190,7 +191,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

0 comments on commit 1990736

Please sign in to comment.