Executes multiple subprocesses simultaneously (Windows only)
Project description
Executes multiple subprocesses concurrently and returns the output and return code of each subprocess. (Windows only)
Tested against Windows 10 / Python 3.10 / Anaconda
pip install multisubprocess
Important: Cannot be executed directly from the console!
from multisubprocess import multi_subprocess
allqueries = []
for q in range(20):
allqueries.append(["ls", "-la", r"E:\textcompare"])
res = multi_subprocess(
allqueries,
byteinput=b"",
shell=False,
close_fds=False,
start_new_session=True,
bufsize=8192 * 40,
invisible=True,
timeout=15,
max_threads=5,
timeout_check_sleep=1,
kill_all_at_end=True,
blockbatch=False,
)
# Output from one subprocess
# from pprint import pprint
# from pprint import pprint
# pprint(res[(7, 'ls', '-la', 'E:\\textcompare')])
# defaultdict(<function <lambda> at 0x00000289E4B15750>,
# {'proc': <Popen: returncode: 0 args: ['ls', '-la', 'E:\\textcompare']>,
# 'returncode': 0,
# 'start': 1682433358.1547163,
# 'stderr': <_io.BytesIO object at 0x00000289EFA2EFC0>,
# 'stderrready': b'',
# 'stdout': <_io.BytesIO object at 0x00000289EFA2EB10>,
# 'stdoutready': b'total 18\ndrwxr-xr-x 1 hansc hansc 0 Apr 24 20:'
# b'33 .\ndrwxr-xr-x 1 hansc hansc 0 Apr 24 20:33 .'
# b'.\n-rw-r--r-- 1 hansc hansc 321 Apr 24 15:41 text'
# b'1.txt\n-rw-r--r-- 1 hansc hansc 367 Apr 24 15:41 '
# b'text2.txt\n'})
Args:
allcommands (str | list): List of commands to execute or one command as a string.
byteinput (bytes, optional): Input to be passed to the subprocess. Defaults to b"".
shell (bool, optional): Whether to use shell to execute the command. Defaults to False.
close_fds (bool, optional): Whether to close file descriptors. Defaults to True.
start_new_session (bool, optional): Whether to start a new session. Defaults to True.
bufsize (int, optional): Buffer size for the subprocess. Defaults to 1024 * 200.
invisible (bool, optional): Whether to run the subprocess invisibly. Defaults to True.
timeout (int, optional): Timeout for the subprocess. Defaults to 10000000.
max_threads (int | None, optional): Maximum number of threads to use. Defaults to None (Number of CPUs).
timeout_check_sleep (int, optional): Sleep time for timeout check. Defaults to 1.
kill_all_at_end (bool, optional): Whether to kill all subprocesses of the main process at the end. Defaults to True.
blockbatch (bool, optional): Whether to block batch processing. Defaults to False.
debug (bool, optional): Whether to print debug information. Defaults to False.
*args: Additional arguments to be passed to subprocess.Popen.
**kwargs: Additional keyword arguments to be passed to subprocess.Popen.
Returns:
dict: A dictionary containing the output and return code of each subprocess.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multisubprocess-0.13.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file multisubprocess-0.13.tar.gz
.
File metadata
- Download URL: multisubprocess-0.13.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134d9a1aa4bd9aacbc3dcea75e18d87e0864cc50887939f6521dd01842cdd558 |
|
MD5 | e51ba414e33573ff568835a1fbff05d8 |
|
BLAKE2b-256 | 683b025987e51219c3fdfbbfbf2616cf074af5401d34823b0739e1326448de61 |
Provenance
File details
Details for the file multisubprocess-0.13-py3-none-any.whl
.
File metadata
- Download URL: multisubprocess-0.13-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e5cbdd95ffa47977c9305936cf0a046e07457a4a410bdc17d41d8cad202ca3e |
|
MD5 | db2937f5d92515f576de2c2b753d381a |
|
BLAKE2b-256 | 42132115dba6f7443c144026564e00457b524d3dd7d537647f5f67cd1966c033 |