44from cyaron .consts import *
55from cyaron .graders import CYaRonGraders
66import subprocess
7+ import multiprocessing
78import sys
89from io import open
910import 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