multiCMD 1.58__tar.gz → 1.60__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {multicmd-1.58 → multicmd-1.60}/PKG-INFO +91 -11
- {multicmd-1.58 → multicmd-1.60}/README.md +90 -10
- {multicmd-1.58 → multicmd-1.60}/multiCMD.egg-info/PKG-INFO +91 -11
- {multicmd-1.58 → multicmd-1.60}/multiCMD.egg-info/SOURCES.txt +3 -0
- {multicmd-1.58 → multicmd-1.60}/multiCMD.py +237 -52
- {multicmd-1.58 → multicmd-1.60}/tests/test_async_executor.py +13 -8
- {multicmd-1.58 → multicmd-1.60}/tests/test_cli.py +13 -5
- multicmd-1.60/tests/test_embed.py +57 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_env.py +28 -9
- multicmd-1.60/tests/test_handover.py +109 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_interrupts.py +222 -85
- multicmd-1.60/tests/test_pass_fds.py +145 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_pool.py +7 -5
- {multicmd-1.58 → multicmd-1.60}/tests/test_run_command.py +3 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_supervision.py +3 -3
- {multicmd-1.58 → multicmd-1.60}/LICENSE +0 -0
- {multicmd-1.58 → multicmd-1.60}/multiCMD.egg-info/dependency_links.txt +0 -0
- {multicmd-1.58 → multicmd-1.60}/multiCMD.egg-info/entry_points.txt +0 -0
- {multicmd-1.58 → multicmd-1.60}/multiCMD.egg-info/top_level.txt +0 -0
- {multicmd-1.58 → multicmd-1.60}/scripts/multiCMD +0 -0
- {multicmd-1.58 → multicmd-1.60}/setup.cfg +0 -0
- {multicmd-1.58 → multicmd-1.60}/setup.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_api.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_cli_input.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_cli_summary.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_display.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_expand_ranges.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_helpers.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_packaging.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_parsing.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_ping.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_process_groups.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_pty.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_reader.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_regressions.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_run_commands.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_sudo.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_task.py +0 -0
- {multicmd-1.58 → multicmd-1.60}/tests/test_windows.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.60
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -326,6 +326,26 @@ overrides. `sudo` resets the environment by default, so with `use_sudo` they may
|
|
|
326
326
|
command. On the command line: `mcmd -e LC_ALL=C -e UNSET_ME "cmd"`; `-n` shows them as
|
|
327
327
|
`env LC_ALL=C cmd` ( `env -i ...` for a whole environment ).
|
|
328
328
|
|
|
329
|
+
### Descriptors a command inherits
|
|
330
|
+
|
|
331
|
+
```python
|
|
332
|
+
fd = os.open("out/file", os.O_WRONLY) # a file this process holds
|
|
333
|
+
multiCMD.run_command(["cp", "src/file", "/dev/fd/%d" % fd], pass_fds=(fd,)) # cp writes it through its own copy
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
`pass_fds` names descriptors the command inherits, at the same numbers, as `subprocess`'s `pass_fds`
|
|
337
|
+
( POSIX only ). It takes an int, an object with `fileno()`, or an iterable of either; the default
|
|
338
|
+
passes nothing, and every descriptor past 2 is closed in the command, as before. It is checked
|
|
339
|
+
before anything runs: a negative, `bool` or closed descriptor is a `ValueError`, and so is any
|
|
340
|
+
off POSIX. multiCMD neither closes nor duplicates them, so keep them open until the command has
|
|
341
|
+
started ( with `wait_for_return=False` or `AsyncExecutor`, until its task's `start_time` is set ).
|
|
342
|
+
The command opens its own copy by name: `/dev/fd/N` ( on Linux `/proc/self/fd/N`, a new open of the
|
|
343
|
+
file; on macOS a `dup` that shares the offset and ignores the open's flags ). With `use_sudo`, sudo
|
|
344
|
+
closes descriptors past 2 unless its policy lets the caller keep them ( `sudo -C`,
|
|
345
|
+
`closefrom_override` ); with `shell=True` the shell inherits them too. `AsyncExecutor` takes it as a
|
|
346
|
+
default a call overrides. There is no command-line form: nothing on a command line holds a
|
|
347
|
+
descriptor.
|
|
348
|
+
|
|
329
349
|
`raise_error=True` raises `multiCMD.CommandError`; its `.tasks` holds the failed `Task`
|
|
330
350
|
objects and its message lists each one with its return code and last error line.
|
|
331
351
|
`Task` also records `start_time`, `end_time` and `duration`. With `dry_run=True` nothing
|
|
@@ -432,15 +452,25 @@ stderr, unless quiet.
|
|
|
432
452
|
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers, nothing
|
|
433
453
|
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
434
454
|
|
|
435
|
-
A command is registered from the moment `Popen` returns it
|
|
436
|
-
|
|
437
|
-
|
|
455
|
+
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
456
|
+
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
457
|
+
starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C (a window of some
|
|
458
|
+
50-70 µs per start) can leave it running, unknown to `kill_all()`. Two Ctrl-Cs microseconds apart can leave a command running, still registered, until
|
|
438
459
|
`kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
|
|
439
460
|
even one at a few points between the steps of a run can leave its command registered but not signalled.
|
|
440
|
-
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a lock can leave it held: one of
|
|
441
|
-
`threading`'s can hang the program as its threads end (CPython's own
|
|
442
|
-
`AsyncExecutor`'s queue, the live output) hangs that
|
|
443
|
-
program keeps going.
|
|
461
|
+
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a C-level lock can leave it held: one of
|
|
462
|
+
`threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
|
|
463
|
+
its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
|
|
464
|
+
executor, or the next call that is not quiet, if the program keeps going.
|
|
465
|
+
A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
|
|
466
|
+
included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
|
|
467
|
+
main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
|
|
468
|
+
call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
|
|
469
|
+
on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2 to 5 ms command, and the same in
|
|
470
|
+
1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
|
|
471
|
+
dropped, about 1 in 700 of those that land there on 3.12 and 3.14 (1.59: 1 in 1,400, and it hung on 3.14): Python
|
|
472
|
+
ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
|
|
473
|
+
Ctrl-C works.
|
|
444
474
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
445
475
|
|
|
446
476
|
## Key functions and objects
|
|
@@ -449,13 +479,14 @@ These and the other known limits are in [docs/limitations.md](docs/limitations.m
|
|
|
449
479
|
run_command(command, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
450
480
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
451
481
|
wait_for_return=True, sem=None, use_sudo=..., raise_error=False,
|
|
452
|
-
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None
|
|
482
|
+
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None,
|
|
483
|
+
pass_fds=())
|
|
453
484
|
|
|
454
485
|
run_commands(commands, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
455
486
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
456
487
|
parse=False, wait_for_return=True, sem=None, use_sudo=...,
|
|
457
488
|
raise_error=False, prefix=False, color=None, pty=False, shell=False,
|
|
458
|
-
env=None, extra_env=None)
|
|
489
|
+
env=None, extra_env=None, pass_fds=())
|
|
459
490
|
|
|
460
491
|
ping(hosts, timeout=1, max_threads=0, ...) # returns True/False reachability
|
|
461
492
|
join_threads(threads=..., timeout=None) # join fire-and-forget threads
|
|
@@ -465,7 +496,7 @@ set_sudo(use_sudo) # enable/disable sudo globally
|
|
|
465
496
|
class Task: # command, returncode, stdout, stderr, start_time, end_time, duration
|
|
466
497
|
class CommandError: # raised by raise_error=True; .tasks = the failed Tasks
|
|
467
498
|
class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, get_return_codes;
|
|
468
|
-
# takes the options above, env / extra_env as defaults a call overrides
|
|
499
|
+
# takes the options above, env / extra_env / pass_fds as defaults a call overrides
|
|
469
500
|
```
|
|
470
501
|
|
|
471
502
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
@@ -491,6 +522,55 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
491
522
|
|
|
492
523
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
493
524
|
|
|
525
|
+
## Upgrading to 1.60 from 1.59
|
|
526
|
+
|
|
527
|
+
- Nothing needs doing to upgrade.
|
|
528
|
+
- Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
|
|
529
|
+
Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
|
|
530
|
+
leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
|
|
531
|
+
blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
|
|
532
|
+
program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
|
|
533
|
+
process, hung 6 of 6 runs with 1.59 on Python 3.14 (after 30 to 9,000 calls) and finished 3 of 3 with 1.60.
|
|
534
|
+
- Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
|
|
535
|
+
fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
|
|
536
|
+
thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
|
|
537
|
+
starts the thread exists), see [docs/limitations.md](docs/limitations.md).
|
|
538
|
+
- A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
|
|
539
|
+
`threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
|
|
540
|
+
reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
|
|
541
|
+
its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
|
|
542
|
+
- The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
|
|
543
|
+
dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
|
|
544
|
+
start on 3.12 and 3.14 and 10 µs on 3.6 with nothing else running (medians: 40 µs against 22 µs on 3.14; 61 µs
|
|
545
|
+
against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
|
|
546
|
+
helper waits for the GIL, and the main thread spends 0.1 to 0.35 ms more per start on 3.12 and 3.14 (0.35 to 1.1 ms
|
|
547
|
+
on 3.6): 2.1 ms against 1.3 ms to start 8 workers on 3.14. The batch as a whole still ends sooner, and a pool is no
|
|
548
|
+
slower for it: 200 `true`s on 16 workers took 35 ms against 47 ms with 1.59 on 3.14, as its readers no longer wait
|
|
549
|
+
for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
|
|
550
|
+
most), so multiCMD knows whether the thread runs.
|
|
551
|
+
- Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
|
|
552
|
+
twice as often as with 1.59 (about 1 in 700 of those that land there, against 1 in 1,400; 1.59 also hung on 3.14
|
|
553
|
+
there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
|
|
554
|
+
[docs/limitations.md](docs/limitations.md).
|
|
555
|
+
- The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
|
|
556
|
+
`multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
|
|
557
|
+
the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
|
|
558
|
+
pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
|
|
559
|
+
|
|
560
|
+
## Upgrading to 1.59 from 1.58
|
|
561
|
+
|
|
562
|
+
- Nothing needs doing to upgrade.
|
|
563
|
+
- Fix, Python 3.6 to 3.10: a Ctrl-C, or what your own signal handler raises (a SIGTERM handler's `sys.exit()`),
|
|
564
|
+
inside `Popen` as a serial run starts a command no longer leaves that command running, unknown to `kill_all()`
|
|
565
|
+
and the exit hook. The exec wrapper now waits for one byte that multiCMD writes on a pipe once the command is
|
|
566
|
+
registered; an interrupted start closes the pipe instead, and the wrapper exits 125 without running anything.
|
|
567
|
+
The window was the whole fork and wait for the exec, about 2.5 ms per start of a large program on 3.6: hpcp's copy
|
|
568
|
+
workers ran 66 such commands in 200 early stops on 3.6 and 33 in 200 on 3.10, and none with 1.59. On 3.11+ the
|
|
569
|
+
window stays (about 50 µs per start; 3 in 200 in the same test), see [docs/limitations.md](docs/limitations.md).
|
|
570
|
+
- New: `pass_fds=` on `run_command`, `run_commands` and `AsyncExecutor` (a constructor default, overridden per call):
|
|
571
|
+
descriptors a command inherits, at the same numbers, as `subprocess`'s `pass_fds` (POSIX only). The default passes
|
|
572
|
+
nothing, as before. See "Descriptors a command inherits" above.
|
|
573
|
+
|
|
494
574
|
## Upgrading to 1.58 from 1.57
|
|
495
575
|
|
|
496
576
|
- The `multiCMD` command is now a script file, not an entry point, so `entry_points.txt` no longer has two names that differ only in case. All three commands still work the same way, except in the venv case below. From 1.58 on, stock pip 9 on EL7 and EL8 upgrades and uninstalls multiCMD without `configparser.DuplicateOptionError`.
|
|
@@ -300,6 +300,26 @@ overrides. `sudo` resets the environment by default, so with `use_sudo` they may
|
|
|
300
300
|
command. On the command line: `mcmd -e LC_ALL=C -e UNSET_ME "cmd"`; `-n` shows them as
|
|
301
301
|
`env LC_ALL=C cmd` ( `env -i ...` for a whole environment ).
|
|
302
302
|
|
|
303
|
+
### Descriptors a command inherits
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
fd = os.open("out/file", os.O_WRONLY) # a file this process holds
|
|
307
|
+
multiCMD.run_command(["cp", "src/file", "/dev/fd/%d" % fd], pass_fds=(fd,)) # cp writes it through its own copy
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`pass_fds` names descriptors the command inherits, at the same numbers, as `subprocess`'s `pass_fds`
|
|
311
|
+
( POSIX only ). It takes an int, an object with `fileno()`, or an iterable of either; the default
|
|
312
|
+
passes nothing, and every descriptor past 2 is closed in the command, as before. It is checked
|
|
313
|
+
before anything runs: a negative, `bool` or closed descriptor is a `ValueError`, and so is any
|
|
314
|
+
off POSIX. multiCMD neither closes nor duplicates them, so keep them open until the command has
|
|
315
|
+
started ( with `wait_for_return=False` or `AsyncExecutor`, until its task's `start_time` is set ).
|
|
316
|
+
The command opens its own copy by name: `/dev/fd/N` ( on Linux `/proc/self/fd/N`, a new open of the
|
|
317
|
+
file; on macOS a `dup` that shares the offset and ignores the open's flags ). With `use_sudo`, sudo
|
|
318
|
+
closes descriptors past 2 unless its policy lets the caller keep them ( `sudo -C`,
|
|
319
|
+
`closefrom_override` ); with `shell=True` the shell inherits them too. `AsyncExecutor` takes it as a
|
|
320
|
+
default a call overrides. There is no command-line form: nothing on a command line holds a
|
|
321
|
+
descriptor.
|
|
322
|
+
|
|
303
323
|
`raise_error=True` raises `multiCMD.CommandError`; its `.tasks` holds the failed `Task`
|
|
304
324
|
objects and its message lists each one with its return code and last error line.
|
|
305
325
|
`Task` also records `start_time`, `end_time` and `duration`. With `dry_run=True` nothing
|
|
@@ -406,15 +426,25 @@ stderr, unless quiet.
|
|
|
406
426
|
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers, nothing
|
|
407
427
|
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
408
428
|
|
|
409
|
-
A command is registered from the moment `Popen` returns it
|
|
410
|
-
|
|
411
|
-
|
|
429
|
+
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
430
|
+
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
431
|
+
starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C (a window of some
|
|
432
|
+
50-70 µs per start) can leave it running, unknown to `kill_all()`. Two Ctrl-Cs microseconds apart can leave a command running, still registered, until
|
|
412
433
|
`kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
|
|
413
434
|
even one at a few points between the steps of a run can leave its command registered but not signalled.
|
|
414
|
-
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a lock can leave it held: one of
|
|
415
|
-
`threading`'s can hang the program as its threads end (CPython's own
|
|
416
|
-
`AsyncExecutor`'s queue, the live output) hangs that
|
|
417
|
-
program keeps going.
|
|
435
|
+
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a C-level lock can leave it held: one of
|
|
436
|
+
`threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
|
|
437
|
+
its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
|
|
438
|
+
executor, or the next call that is not quiet, if the program keeps going.
|
|
439
|
+
A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
|
|
440
|
+
included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
|
|
441
|
+
main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
|
|
442
|
+
call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
|
|
443
|
+
on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2 to 5 ms command, and the same in
|
|
444
|
+
1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
|
|
445
|
+
dropped, about 1 in 700 of those that land there on 3.12 and 3.14 (1.59: 1 in 1,400, and it hung on 3.14): Python
|
|
446
|
+
ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
|
|
447
|
+
Ctrl-C works.
|
|
418
448
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
419
449
|
|
|
420
450
|
## Key functions and objects
|
|
@@ -423,13 +453,14 @@ These and the other known limits are in [docs/limitations.md](docs/limitations.m
|
|
|
423
453
|
run_command(command, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
424
454
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
425
455
|
wait_for_return=True, sem=None, use_sudo=..., raise_error=False,
|
|
426
|
-
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None
|
|
456
|
+
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None,
|
|
457
|
+
pass_fds=())
|
|
427
458
|
|
|
428
459
|
run_commands(commands, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
429
460
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
430
461
|
parse=False, wait_for_return=True, sem=None, use_sudo=...,
|
|
431
462
|
raise_error=False, prefix=False, color=None, pty=False, shell=False,
|
|
432
|
-
env=None, extra_env=None)
|
|
463
|
+
env=None, extra_env=None, pass_fds=())
|
|
433
464
|
|
|
434
465
|
ping(hosts, timeout=1, max_threads=0, ...) # returns True/False reachability
|
|
435
466
|
join_threads(threads=..., timeout=None) # join fire-and-forget threads
|
|
@@ -439,7 +470,7 @@ set_sudo(use_sudo) # enable/disable sudo globally
|
|
|
439
470
|
class Task: # command, returncode, stdout, stderr, start_time, end_time, duration
|
|
440
471
|
class CommandError: # raised by raise_error=True; .tasks = the failed Tasks
|
|
441
472
|
class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, get_return_codes;
|
|
442
|
-
# takes the options above, env / extra_env as defaults a call overrides
|
|
473
|
+
# takes the options above, env / extra_env / pass_fds as defaults a call overrides
|
|
443
474
|
```
|
|
444
475
|
|
|
445
476
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
@@ -465,6 +496,55 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
465
496
|
|
|
466
497
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
467
498
|
|
|
499
|
+
## Upgrading to 1.60 from 1.59
|
|
500
|
+
|
|
501
|
+
- Nothing needs doing to upgrade.
|
|
502
|
+
- Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
|
|
503
|
+
Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
|
|
504
|
+
leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
|
|
505
|
+
blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
|
|
506
|
+
program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
|
|
507
|
+
process, hung 6 of 6 runs with 1.59 on Python 3.14 (after 30 to 9,000 calls) and finished 3 of 3 with 1.60.
|
|
508
|
+
- Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
|
|
509
|
+
fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
|
|
510
|
+
thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
|
|
511
|
+
starts the thread exists), see [docs/limitations.md](docs/limitations.md).
|
|
512
|
+
- A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
|
|
513
|
+
`threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
|
|
514
|
+
reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
|
|
515
|
+
its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
|
|
516
|
+
- The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
|
|
517
|
+
dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
|
|
518
|
+
start on 3.12 and 3.14 and 10 µs on 3.6 with nothing else running (medians: 40 µs against 22 µs on 3.14; 61 µs
|
|
519
|
+
against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
|
|
520
|
+
helper waits for the GIL, and the main thread spends 0.1 to 0.35 ms more per start on 3.12 and 3.14 (0.35 to 1.1 ms
|
|
521
|
+
on 3.6): 2.1 ms against 1.3 ms to start 8 workers on 3.14. The batch as a whole still ends sooner, and a pool is no
|
|
522
|
+
slower for it: 200 `true`s on 16 workers took 35 ms against 47 ms with 1.59 on 3.14, as its readers no longer wait
|
|
523
|
+
for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
|
|
524
|
+
most), so multiCMD knows whether the thread runs.
|
|
525
|
+
- Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
|
|
526
|
+
twice as often as with 1.59 (about 1 in 700 of those that land there, against 1 in 1,400; 1.59 also hung on 3.14
|
|
527
|
+
there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
|
|
528
|
+
[docs/limitations.md](docs/limitations.md).
|
|
529
|
+
- The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
|
|
530
|
+
`multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
|
|
531
|
+
the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
|
|
532
|
+
pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
|
|
533
|
+
|
|
534
|
+
## Upgrading to 1.59 from 1.58
|
|
535
|
+
|
|
536
|
+
- Nothing needs doing to upgrade.
|
|
537
|
+
- Fix, Python 3.6 to 3.10: a Ctrl-C, or what your own signal handler raises (a SIGTERM handler's `sys.exit()`),
|
|
538
|
+
inside `Popen` as a serial run starts a command no longer leaves that command running, unknown to `kill_all()`
|
|
539
|
+
and the exit hook. The exec wrapper now waits for one byte that multiCMD writes on a pipe once the command is
|
|
540
|
+
registered; an interrupted start closes the pipe instead, and the wrapper exits 125 without running anything.
|
|
541
|
+
The window was the whole fork and wait for the exec, about 2.5 ms per start of a large program on 3.6: hpcp's copy
|
|
542
|
+
workers ran 66 such commands in 200 early stops on 3.6 and 33 in 200 on 3.10, and none with 1.59. On 3.11+ the
|
|
543
|
+
window stays (about 50 µs per start; 3 in 200 in the same test), see [docs/limitations.md](docs/limitations.md).
|
|
544
|
+
- New: `pass_fds=` on `run_command`, `run_commands` and `AsyncExecutor` (a constructor default, overridden per call):
|
|
545
|
+
descriptors a command inherits, at the same numbers, as `subprocess`'s `pass_fds` (POSIX only). The default passes
|
|
546
|
+
nothing, as before. See "Descriptors a command inherits" above.
|
|
547
|
+
|
|
468
548
|
## Upgrading to 1.58 from 1.57
|
|
469
549
|
|
|
470
550
|
- The `multiCMD` command is now a script file, not an entry point, so `entry_points.txt` no longer has two names that differ only in case. All three commands still work the same way, except in the venv case below. From 1.58 on, stock pip 9 on EL7 and EL8 upgrades and uninstalls multiCMD without `configparser.DuplicateOptionError`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.60
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -326,6 +326,26 @@ overrides. `sudo` resets the environment by default, so with `use_sudo` they may
|
|
|
326
326
|
command. On the command line: `mcmd -e LC_ALL=C -e UNSET_ME "cmd"`; `-n` shows them as
|
|
327
327
|
`env LC_ALL=C cmd` ( `env -i ...` for a whole environment ).
|
|
328
328
|
|
|
329
|
+
### Descriptors a command inherits
|
|
330
|
+
|
|
331
|
+
```python
|
|
332
|
+
fd = os.open("out/file", os.O_WRONLY) # a file this process holds
|
|
333
|
+
multiCMD.run_command(["cp", "src/file", "/dev/fd/%d" % fd], pass_fds=(fd,)) # cp writes it through its own copy
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
`pass_fds` names descriptors the command inherits, at the same numbers, as `subprocess`'s `pass_fds`
|
|
337
|
+
( POSIX only ). It takes an int, an object with `fileno()`, or an iterable of either; the default
|
|
338
|
+
passes nothing, and every descriptor past 2 is closed in the command, as before. It is checked
|
|
339
|
+
before anything runs: a negative, `bool` or closed descriptor is a `ValueError`, and so is any
|
|
340
|
+
off POSIX. multiCMD neither closes nor duplicates them, so keep them open until the command has
|
|
341
|
+
started ( with `wait_for_return=False` or `AsyncExecutor`, until its task's `start_time` is set ).
|
|
342
|
+
The command opens its own copy by name: `/dev/fd/N` ( on Linux `/proc/self/fd/N`, a new open of the
|
|
343
|
+
file; on macOS a `dup` that shares the offset and ignores the open's flags ). With `use_sudo`, sudo
|
|
344
|
+
closes descriptors past 2 unless its policy lets the caller keep them ( `sudo -C`,
|
|
345
|
+
`closefrom_override` ); with `shell=True` the shell inherits them too. `AsyncExecutor` takes it as a
|
|
346
|
+
default a call overrides. There is no command-line form: nothing on a command line holds a
|
|
347
|
+
descriptor.
|
|
348
|
+
|
|
329
349
|
`raise_error=True` raises `multiCMD.CommandError`; its `.tasks` holds the failed `Task`
|
|
330
350
|
objects and its message lists each one with its return code and last error line.
|
|
331
351
|
`Task` also records `start_time`, `end_time` and `duration`. With `dry_run=True` nothing
|
|
@@ -432,15 +452,25 @@ stderr, unless quiet.
|
|
|
432
452
|
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers, nothing
|
|
433
453
|
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
434
454
|
|
|
435
|
-
A command is registered from the moment `Popen` returns it
|
|
436
|
-
|
|
437
|
-
|
|
455
|
+
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
456
|
+
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
457
|
+
starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C (a window of some
|
|
458
|
+
50-70 µs per start) can leave it running, unknown to `kill_all()`. Two Ctrl-Cs microseconds apart can leave a command running, still registered, until
|
|
438
459
|
`kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
|
|
439
460
|
even one at a few points between the steps of a run can leave its command registered but not signalled.
|
|
440
|
-
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a lock can leave it held: one of
|
|
441
|
-
`threading`'s can hang the program as its threads end (CPython's own
|
|
442
|
-
`AsyncExecutor`'s queue, the live output) hangs that
|
|
443
|
-
program keeps going.
|
|
461
|
+
On Python 3.6-3.9 and 3.14 a Ctrl-C at the wrong instruction of a `with` on a C-level lock can leave it held: one of
|
|
462
|
+
`threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
|
|
463
|
+
its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
|
|
464
|
+
executor, or the next call that is not quiet, if the program keeps going.
|
|
465
|
+
A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
|
|
466
|
+
included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
|
|
467
|
+
main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
|
|
468
|
+
call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
|
|
469
|
+
on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2 to 5 ms command, and the same in
|
|
470
|
+
1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
|
|
471
|
+
dropped, about 1 in 700 of those that land there on 3.12 and 3.14 (1.59: 1 in 1,400, and it hung on 3.14): Python
|
|
472
|
+
ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
|
|
473
|
+
Ctrl-C works.
|
|
444
474
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
445
475
|
|
|
446
476
|
## Key functions and objects
|
|
@@ -449,13 +479,14 @@ These and the other known limits are in [docs/limitations.md](docs/limitations.m
|
|
|
449
479
|
run_command(command, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
450
480
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
451
481
|
wait_for_return=True, sem=None, use_sudo=..., raise_error=False,
|
|
452
|
-
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None
|
|
482
|
+
prefix=False, color=None, pty=False, shell=False, env=None, extra_env=None,
|
|
483
|
+
pass_fds=())
|
|
453
484
|
|
|
454
485
|
run_commands(commands, timeout=0, max_threads=1, quiet=False, dry_run=False,
|
|
455
486
|
with_stdErr=False, return_code_only=False, return_object=False,
|
|
456
487
|
parse=False, wait_for_return=True, sem=None, use_sudo=...,
|
|
457
488
|
raise_error=False, prefix=False, color=None, pty=False, shell=False,
|
|
458
|
-
env=None, extra_env=None)
|
|
489
|
+
env=None, extra_env=None, pass_fds=())
|
|
459
490
|
|
|
460
491
|
ping(hosts, timeout=1, max_threads=0, ...) # returns True/False reachability
|
|
461
492
|
join_threads(threads=..., timeout=None) # join fire-and-forget threads
|
|
@@ -465,7 +496,7 @@ set_sudo(use_sudo) # enable/disable sudo globally
|
|
|
465
496
|
class Task: # command, returncode, stdout, stderr, start_time, end_time, duration
|
|
466
497
|
class CommandError: # raised by raise_error=True; .tasks = the failed Tasks
|
|
467
498
|
class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, get_return_codes;
|
|
468
|
-
# takes the options above, env / extra_env as defaults a call overrides
|
|
499
|
+
# takes the options above, env / extra_env / pass_fds as defaults a call overrides
|
|
469
500
|
```
|
|
470
501
|
|
|
471
502
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
@@ -491,6 +522,55 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
491
522
|
|
|
492
523
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
493
524
|
|
|
525
|
+
## Upgrading to 1.60 from 1.59
|
|
526
|
+
|
|
527
|
+
- Nothing needs doing to upgrade.
|
|
528
|
+
- Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
|
|
529
|
+
Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
|
|
530
|
+
leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
|
|
531
|
+
blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
|
|
532
|
+
program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
|
|
533
|
+
process, hung 6 of 6 runs with 1.59 on Python 3.14 (after 30 to 9,000 calls) and finished 3 of 3 with 1.60.
|
|
534
|
+
- Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
|
|
535
|
+
fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
|
|
536
|
+
thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
|
|
537
|
+
starts the thread exists), see [docs/limitations.md](docs/limitations.md).
|
|
538
|
+
- A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
|
|
539
|
+
`threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
|
|
540
|
+
reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
|
|
541
|
+
its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
|
|
542
|
+
- The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
|
|
543
|
+
dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
|
|
544
|
+
start on 3.12 and 3.14 and 10 µs on 3.6 with nothing else running (medians: 40 µs against 22 µs on 3.14; 61 µs
|
|
545
|
+
against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
|
|
546
|
+
helper waits for the GIL, and the main thread spends 0.1 to 0.35 ms more per start on 3.12 and 3.14 (0.35 to 1.1 ms
|
|
547
|
+
on 3.6): 2.1 ms against 1.3 ms to start 8 workers on 3.14. The batch as a whole still ends sooner, and a pool is no
|
|
548
|
+
slower for it: 200 `true`s on 16 workers took 35 ms against 47 ms with 1.59 on 3.14, as its readers no longer wait
|
|
549
|
+
for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
|
|
550
|
+
most), so multiCMD knows whether the thread runs.
|
|
551
|
+
- Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
|
|
552
|
+
twice as often as with 1.59 (about 1 in 700 of those that land there, against 1 in 1,400; 1.59 also hung on 3.14
|
|
553
|
+
there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
|
|
554
|
+
[docs/limitations.md](docs/limitations.md).
|
|
555
|
+
- The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
|
|
556
|
+
`multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
|
|
557
|
+
the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
|
|
558
|
+
pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
|
|
559
|
+
|
|
560
|
+
## Upgrading to 1.59 from 1.58
|
|
561
|
+
|
|
562
|
+
- Nothing needs doing to upgrade.
|
|
563
|
+
- Fix, Python 3.6 to 3.10: a Ctrl-C, or what your own signal handler raises (a SIGTERM handler's `sys.exit()`),
|
|
564
|
+
inside `Popen` as a serial run starts a command no longer leaves that command running, unknown to `kill_all()`
|
|
565
|
+
and the exit hook. The exec wrapper now waits for one byte that multiCMD writes on a pipe once the command is
|
|
566
|
+
registered; an interrupted start closes the pipe instead, and the wrapper exits 125 without running anything.
|
|
567
|
+
The window was the whole fork and wait for the exec, about 2.5 ms per start of a large program on 3.6: hpcp's copy
|
|
568
|
+
workers ran 66 such commands in 200 early stops on 3.6 and 33 in 200 on 3.10, and none with 1.59. On 3.11+ the
|
|
569
|
+
window stays (about 50 µs per start; 3 in 200 in the same test), see [docs/limitations.md](docs/limitations.md).
|
|
570
|
+
- New: `pass_fds=` on `run_command`, `run_commands` and `AsyncExecutor` (a constructor default, overridden per call):
|
|
571
|
+
descriptors a command inherits, at the same numbers, as `subprocess`'s `pass_fds` (POSIX only). The default passes
|
|
572
|
+
nothing, as before. See "Descriptors a command inherits" above.
|
|
573
|
+
|
|
494
574
|
## Upgrading to 1.58 from 1.57
|
|
495
575
|
|
|
496
576
|
- The `multiCMD` command is now a script file, not an entry point, so `entry_points.txt` no longer has two names that differ only in case. All three commands still work the same way, except in the venv case below. From 1.58 on, stock pip 9 on EL7 and EL8 upgrades and uninstalls multiCMD without `configparser.DuplicateOptionError`.
|
|
@@ -14,12 +14,15 @@ tests/test_cli.py
|
|
|
14
14
|
tests/test_cli_input.py
|
|
15
15
|
tests/test_cli_summary.py
|
|
16
16
|
tests/test_display.py
|
|
17
|
+
tests/test_embed.py
|
|
17
18
|
tests/test_env.py
|
|
18
19
|
tests/test_expand_ranges.py
|
|
20
|
+
tests/test_handover.py
|
|
19
21
|
tests/test_helpers.py
|
|
20
22
|
tests/test_interrupts.py
|
|
21
23
|
tests/test_packaging.py
|
|
22
24
|
tests/test_parsing.py
|
|
25
|
+
tests/test_pass_fds.py
|
|
23
26
|
tests/test_ping.py
|
|
24
27
|
tests/test_pool.py
|
|
25
28
|
tests/test_process_groups.py
|