при выполнении возникает ошибка:
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
========================== RESTART: D:\workdir\run.py ==========================
Queued range (100000000, 100099999)
Queued range (100100000, 100199999)
Queued range (100200000, 100299999)
Queued range (100300000, 100399999)
Queued range (100400000, 100499999)
Queued all 5 tasks
Thread {'tid': 1} starting task (100000000, 100099999)...Thread {'tid': 2} starting task (100100000, 100199999)...Thread {'tid': 3} starting task (100200000, 100299999)...Thread {'tid': 4} starting task (100300000, 100399999)....
Thread {'tid': 1} starting task (100400000, 100499999)...
Traceback (most recent call last):
File "C:\python\lib\concurrent\futures\_base.py", line 451, in result
return self.__get_result()
File "C:\python\lib\concurrent\futures\_base.py", line 403, in __get_result
raise self._exception
File "C:\python\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "D:\workdir\run.py", line 56, in bruteforce_range
proc = subprocess.run(cmdline, cwd=WORKING_DIR)
File "C:\python\lib\subprocess.py", line 503, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\python\lib\subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\python\lib\subprocess.py", line 1440, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
код:
from concurrent.futures import ThreadPoolExecutor, wait, as_completed
import os
from shutil import rmtree, copytree
import threading
import time
import subprocess
SASFOUNDATION = r'D:\SAS94\SASFoundation\9.4\core'
WORKING_DIR = r'D:\workdir'
START_NUMBER = 100000000
END_NUMBER = 100500000 - 1
#END_NUMBER = 120000000
BATCH_SIZE = 100000
THREAD_COUNT = 4
thread_num = 0
lck = threading.Lock()
sess = threading.local()
def prepare_env():
for i in range(1, THREAD_COUNT + 1):
if os.path.exists(f"{WORKING_DIR}/sashelp_{i}"):
rmtree(f"{WORKING_DIR}/sashelp_{i}")
copytree(f"{SASFOUNDATION}/sashelp", f"{WORKING_DIR}/sashelp_{i}")
def bruteforce_range(range_tuple):
if 'tid' not in sess.__dict__:
global thread_num
with lck:
thread_num += 1
sess.tid = thread_num
print(f"Thread {sess.__dict__} starting task {range_tuple}...")
cmdline = [f"{SASFOUNDATION}/sas",
"-SYSIN", f"{WORKING_DIR}/m_bruteforce_sid.sas",
"-SET", "THREAD_ID", f"{sess.tid}",
"-SET", "START_NUM", f"{range_tuple[0]}",
"-SET", "END_NUM", f"{range_tuple[1]}",
"-noautoexec",
"-log", "/dev/null",
#"-log", f"{WORKING_DIR}/m_bruteforce_sid_{sess.tid}.log",
"-logparm", """write=immediate""",
#"-FILELOCKS", "NONE",
#"-NOWORKINIT",
"-SASHELP", f"{WORKING_DIR}/sashelp_{sess.tid}"]
proc = subprocess.run(cmdline, cwd=WORKING_DIR)
print(proc)
print(f"Thread {sess.__dict__} finished task {range_tuple}")
return (sess.tid, range_tuple, proc.returncode)
def main():
chunks = []
for i in range(START_NUMBER, END_NUMBER, BATCH_SIZE):
rng = (i, i + BATCH_SIZE - 1)
chunks.append(rng)
print(f"Queued range {rng}")
print(f"Queued all {len(chunks)} tasks")
prepare_env()
begin = time.time()
with ThreadPoolExecutor(max_workers=THREAD_COUNT) as executor:
#results = executor.map(bruteforce_range, chunks)
futures = [executor.submit(bruteforce_range, chunk) for chunk in chunks]
#print(results)
for res in as_completed(futures):
tid, chunk, rc = res.result()
print(f"Thread {tid} completed batch {chunk} after {time.time() - begin} seconds with resultcode {rc}")
main()