Move available_cpu_count to helpers

This commit is contained in:
James R. Barlow
2018-03-23 13:07:51 -07:00
parent dfeb8812ad
commit 4f1f3b9b51
2 changed files with 21 additions and 19 deletions
+2 -19
View File
@@ -23,7 +23,8 @@ import ruffus.proxy_logger as proxy_logger
from .pipeline import JobContext, JobContextManager, \
cleanup_working_files, build_pipeline
from .pdfa import file_claims_pdfa
from .helpers import is_iterable_notstr, re_symlink, is_file_writable
from .helpers import is_iterable_notstr, re_symlink, is_file_writable, \
available_cpu_count
from .exec import tesseract, qpdf, ghostscript
from . import PROGRAM_NAME, VERSION
@@ -531,24 +532,6 @@ def logging_factory(logger_name, logger_args):
return root_logger
def available_cpu_count():
try:
return multiprocessing.cpu_count()
except NotImplementedError:
pass
try:
import psutil
return psutil.cpu_count()
except (ImportError, AttributeError):
pass
complain(
"Could not get CPU count. Assuming one (1) CPU."
"Use -j N to set manually.")
return 1
def cleanup_ruffus_error_message(msg):
msg = re.sub(r'\s+', r' ', msg)
msg = re.sub(r"\((.+?)\)", r'\1', msg)
+19
View File
@@ -6,6 +6,7 @@ from contextlib import suppress, contextmanager
from pathlib import Path
import sys
import os
import multiprocessing
def re_symlink(input_file, soft_link_name, log=None):
@@ -57,6 +58,24 @@ def page_number(input_file):
return int(os.path.basename(input_file)[0:6])
def available_cpu_count():
try:
return multiprocessing.cpu_count()
except NotImplementedError:
pass
try:
import psutil
return psutil.cpu_count()
except (ImportError, AttributeError):
pass
complain(
"Could not get CPU count. Assuming one (1) CPU."
"Use -j N to set manually.")
return 1
def is_file_writable(test_file):
"""Intentionally racy test if target is writable.