Skip to content

Commit 59b9470

Browse files
author
TitanSnow
committed
fix max_workers in python3.4-
1 parent fb7ba26 commit 59b9470

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cyaron/compare.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from cyaron.consts import *
55
from cyaron.graders import CYaRonGraders
66
import subprocess
7+
import multiprocessing
78
import sys
89
from io import open
910
import os
@@ -29,6 +30,14 @@ def __process_file(file):
2930
with open(file, "r", newline='\n') as f:
3031
return file, f.read()
3132

33+
@staticmethod
34+
def __normal_max_workers(workers):
35+
if workers is None:
36+
if sys.version_info < (3, 5):
37+
cpu = multiprocessing.cpu_count()
38+
return cpu * 5 if cpu is not None else 1
39+
return workers
40+
3241
@classmethod
3342
def output(cls, *files, **kwargs):
3443
kwargs = unpack_kwargs('output', kwargs, ('std', ('grader', DEFAULT_GRADER), ('max_workers', -1), ('job_pool', None)))
@@ -37,6 +46,7 @@ def output(cls, *files, **kwargs):
3746
max_workers = kwargs['max_workers']
3847
job_pool = kwargs['job_pool']
3948
if (max_workers is None or max_workers >= 0) and job_pool is None:
49+
max_workers = cls.__normal_max_workers(max_workers)
4050
try:
4151
from concurrent.futures import ThreadPoolExecutor
4252
with ThreadPoolExecutor(max_workers=max_workers) as job_pool:
@@ -70,6 +80,7 @@ def program(cls, *programs, **kwargs):
7080
max_workers = kwargs['max_workers']
7181
job_pool = kwargs['job_pool']
7282
if (max_workers is None or max_workers >= 0) and job_pool is None:
83+
max_workers = cls.__normal_max_workers(max_workers)
7384
try:
7485
from concurrent.futures import ThreadPoolExecutor
7586
with ThreadPoolExecutor(max_workers=max_workers) as job_pool:

0 commit comments

Comments
 (0)