multiCMD 1.59__tar.gz → 1.61__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.
Files changed (40) hide show
  1. {multicmd-1.59 → multicmd-1.61}/PKG-INFO +100 -6
  2. {multicmd-1.59 → multicmd-1.61}/README.md +99 -5
  3. {multicmd-1.59 → multicmd-1.61}/multiCMD.egg-info/PKG-INFO +100 -6
  4. {multicmd-1.59 → multicmd-1.61}/multiCMD.egg-info/SOURCES.txt +2 -0
  5. {multicmd-1.59 → multicmd-1.61}/multiCMD.py +235 -35
  6. {multicmd-1.59 → multicmd-1.61}/tests/test_async_executor.py +13 -8
  7. {multicmd-1.59 → multicmd-1.61}/tests/test_cli.py +13 -5
  8. multicmd-1.61/tests/test_cli_closed_stdout.py +449 -0
  9. {multicmd-1.59 → multicmd-1.61}/tests/test_display.py +48 -0
  10. multicmd-1.61/tests/test_embed.py +57 -0
  11. {multicmd-1.59 → multicmd-1.61}/tests/test_env.py +6 -2
  12. {multicmd-1.59 → multicmd-1.61}/tests/test_handover.py +38 -0
  13. {multicmd-1.59 → multicmd-1.61}/tests/test_interrupts.py +222 -85
  14. {multicmd-1.59 → multicmd-1.61}/tests/test_pool.py +7 -5
  15. {multicmd-1.59 → multicmd-1.61}/tests/test_process_groups.py +27 -1
  16. {multicmd-1.59 → multicmd-1.61}/tests/test_supervision.py +3 -3
  17. {multicmd-1.59 → multicmd-1.61}/LICENSE +0 -0
  18. {multicmd-1.59 → multicmd-1.61}/multiCMD.egg-info/dependency_links.txt +0 -0
  19. {multicmd-1.59 → multicmd-1.61}/multiCMD.egg-info/entry_points.txt +0 -0
  20. {multicmd-1.59 → multicmd-1.61}/multiCMD.egg-info/top_level.txt +0 -0
  21. {multicmd-1.59 → multicmd-1.61}/scripts/multiCMD +0 -0
  22. {multicmd-1.59 → multicmd-1.61}/setup.cfg +0 -0
  23. {multicmd-1.59 → multicmd-1.61}/setup.py +0 -0
  24. {multicmd-1.59 → multicmd-1.61}/tests/test_api.py +0 -0
  25. {multicmd-1.59 → multicmd-1.61}/tests/test_cli_input.py +0 -0
  26. {multicmd-1.59 → multicmd-1.61}/tests/test_cli_summary.py +0 -0
  27. {multicmd-1.59 → multicmd-1.61}/tests/test_expand_ranges.py +0 -0
  28. {multicmd-1.59 → multicmd-1.61}/tests/test_helpers.py +0 -0
  29. {multicmd-1.59 → multicmd-1.61}/tests/test_packaging.py +0 -0
  30. {multicmd-1.59 → multicmd-1.61}/tests/test_parsing.py +0 -0
  31. {multicmd-1.59 → multicmd-1.61}/tests/test_pass_fds.py +0 -0
  32. {multicmd-1.59 → multicmd-1.61}/tests/test_ping.py +0 -0
  33. {multicmd-1.59 → multicmd-1.61}/tests/test_pty.py +0 -0
  34. {multicmd-1.59 → multicmd-1.61}/tests/test_reader.py +0 -0
  35. {multicmd-1.59 → multicmd-1.61}/tests/test_regressions.py +0 -0
  36. {multicmd-1.59 → multicmd-1.61}/tests/test_run_command.py +0 -0
  37. {multicmd-1.59 → multicmd-1.61}/tests/test_run_commands.py +0 -0
  38. {multicmd-1.59 → multicmd-1.61}/tests/test_sudo.py +0 -0
  39. {multicmd-1.59 → multicmd-1.61}/tests/test_task.py +0 -0
  40. {multicmd-1.59 → multicmd-1.61}/tests/test_windows.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.59
3
+ Version: 1.61
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -119,6 +119,7 @@ exit status:
119
119
  N several commands: how many failed, capped at 101
120
120
  2 usage error
121
121
  130 interrupted with Ctrl-C ( 128+S after SIGTERM / SIGHUP )
122
+ 141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows, untested there )
122
123
  ```
123
124
 
124
125
  ### Examples
@@ -192,6 +193,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
192
193
  | Several commands | the number that failed, capped at `101` |
193
194
  | Usage error (bad option, unbalanced quote, no commands) | `2` |
194
195
  | Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
196
+ | stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows (untested there) |
195
197
 
196
198
  ### Input files and templates
197
199
 
@@ -441,7 +443,11 @@ Signals sent to your program's group do not reach the commands, so multiCMD stop
441
443
  Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main thread, `join_threads()`
442
444
  and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
443
445
  re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
444
- commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`). At interpreter exit
446
+ commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
447
+ has no reader (`mcmd ... | head`): it stops them as a Ctrl-C does, and ends by SIGPIPE, as `yes | head` does, with
448
+ nothing on stderr. It learns that stdout has no reader only when a write to it fails, so a command that prints nothing
449
+ more runs to its end first (`mcmd 'sleep 4' | head -2` takes 4 s, as `sleep 4 | head -2` does). A program that imports
450
+ multiCMD still gets the `BrokenPipeError`. At interpreter exit
445
451
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
446
452
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
447
453
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -458,10 +464,23 @@ starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C
458
464
  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
459
465
  `kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
460
466
  even one at a few points between the steps of a run can leave its command registered but not signalled.
461
- 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
462
- `threading`'s can hang the program as its threads end (CPython's own), and one of multiCMD's (an
463
- `AsyncExecutor`'s queue, the live output) hangs that executor, or the next call that is not quiet, if the
464
- program keeps going.
467
+ 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
468
+ `threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
469
+ its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
470
+ executor, or the next call that is not quiet, if the program keeps going.
471
+ A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
472
+ included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
473
+ main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
474
+ call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
475
+ 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
476
+ 1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
477
+ 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
478
+ ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
479
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
480
+ about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): the same message, and the next Ctrl-C works. On Python 3.6-3.10 a
481
+ Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen`, normally about 1 ms (2-5 ms at p99); if the
482
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
483
+ answers.
465
484
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
466
485
 
467
486
  ## Key functions and objects
@@ -513,6 +532,81 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
513
532
 
514
533
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
515
534
 
535
+ ## Upgrading to 1.61 from 1.60
536
+
537
+ - Nothing needs doing to upgrade.
538
+ - Fix: `mcmd ... | head` (a reader that quits early) ends quietly. It printed a traceback or an "Exception ignored" message
539
+ and exited 120 (Python's status for a stdout it cannot flush), and the commands were left to run on: a quiet one,
540
+ or one that ignores SIGPIPE, ran to its end or for ever, with `mcmd` waiting for it. Now `mcmd` stops the commands as a
541
+ Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
542
+ Windows, untested: a closed pipe may show there as an `OSError` that `mcmd` does not catch yet, planned for 1.62). It
543
+ covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions still raise
544
+ `BrokenPipeError` when `sys.stdout` fails. A thread that finds stdout closed only says so, and the main thread's
545
+ waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
546
+ `mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
547
+ drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
548
+ the reader quit (`mcmd 'sleep 4' | head -2`, a `-q` run, one under `-t`) runs to its end first, as it did, and then
549
+ `mcmd` ends 141. Planned for 1.62: asking the pipe instead of waiting for a write.
550
+ - Changed: a closed stderr with a working stdout can now end `mcmd` by SIGPIPE (141) when `mcmd` itself prints an error
551
+ there; it ended 120 with 1.60. Measured: on 3.9 and 3.10 an unbalanced quote, a usage error and "no commands given" all
552
+ end 141; on 3.12 and 3.14 only the unbalanced quote does, as argparse's own errors stay 120; on 3.6 nothing changes
553
+ (all 120). The error of a command that cannot run ends as before on every Python.
554
+ - Fix, Python 3.6 to 3.10: a stop (a Ctrl-C, `stop()`, `kill_all(signal.SIGINT)`) that lands as a command starts no
555
+ longer crashes the exec wrapper's Python. A stop sends SIGINT first, and a Python that SIGINT reaches while it
556
+ initializes aborts with a core dump on 3.6 and 3.7 ("Fatal Python error: ... can't initialize sys standard streams")
557
+ and exits 1 with that message on 3.8 to 3.10; a little later in its start it prints a `KeyboardInterrupt` traceback.
558
+ Each landed in that command's stderr, and each core dump in the host's crash handler (systemd-coredump, apport, abrt).
559
+ Aimed at random into 400 starts each with 1.60: 80 aborted on 3.6 (1.59 the same) and 63 on 3.7; 54, 41 and 42 exited
560
+ with "Fatal Python error" on 3.8, 3.9 and 3.10; with 1.61 every one ended by SIGINT or ran to its end, without a
561
+ word. It is not new: every version with the exec wrapper (1.52 on) had it. The wrapper now starts with SIGINT
562
+ blocked and unblocks it once it has the command, so such a stop ends it by SIGINT, as it ends the command; a command
563
+ still inherits SIGINT blocked from a calling thread that has it blocked. On GitHub's runners the core dumps of
564
+ 1.60's new stop test (5,000 stops in one process) each started an apport process, which drove the load to 250 and
565
+ timed the 3.6 job out.
566
+ - Known: on Python 3.6 to 3.10 a Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen` (the fork,
567
+ the exec of the Python binary, the read of its error pipe), normally about 1 ms (2 to 5 ms at p99), where 1.60 stopped
568
+ at once. If the exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), Ctrl-C does
569
+ nothing until the mount answers; 1.60 exited 130. See [docs/limitations.md](docs/limitations.md).
570
+ - Known: a Ctrl-C that lands in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished, in a serial run, is
571
+ dropped (12 of about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): Python prints "Exception ignored" and the run goes
572
+ on; press it again. It is the dropped Ctrl-C of 1.60's note below, in serial runs too. See
573
+ [docs/limitations.md](docs/limitations.md).
574
+
575
+ ## Upgrading to 1.60 from 1.59
576
+
577
+ - Nothing needs doing to upgrade.
578
+ - Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
579
+ Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
580
+ leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
581
+ blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
582
+ program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
583
+ 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.
584
+ - Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
585
+ fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
586
+ thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
587
+ starts the thread exists), see [docs/limitations.md](docs/limitations.md).
588
+ - A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
589
+ `threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
590
+ reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
591
+ its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
592
+ - The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
593
+ dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
594
+ 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
595
+ against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
596
+ 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
597
+ 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
598
+ 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
599
+ for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
600
+ most), so multiCMD knows whether the thread runs.
601
+ - Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
602
+ 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
603
+ there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
604
+ [docs/limitations.md](docs/limitations.md).
605
+ - The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
606
+ `multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
607
+ the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
608
+ pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
609
+
516
610
  ## Upgrading to 1.59 from 1.58
517
611
 
518
612
  - Nothing needs doing to upgrade.
@@ -93,6 +93,7 @@ exit status:
93
93
  N several commands: how many failed, capped at 101
94
94
  2 usage error
95
95
  130 interrupted with Ctrl-C ( 128+S after SIGTERM / SIGHUP )
96
+ 141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows, untested there )
96
97
  ```
97
98
 
98
99
  ### Examples
@@ -166,6 +167,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
166
167
  | Several commands | the number that failed, capped at `101` |
167
168
  | Usage error (bad option, unbalanced quote, no commands) | `2` |
168
169
  | Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
170
+ | stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows (untested there) |
169
171
 
170
172
  ### Input files and templates
171
173
 
@@ -415,7 +417,11 @@ Signals sent to your program's group do not reach the commands, so multiCMD stop
415
417
  Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main thread, `join_threads()`
416
418
  and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
417
419
  re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
418
- commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`). At interpreter exit
420
+ commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
421
+ has no reader (`mcmd ... | head`): it stops them as a Ctrl-C does, and ends by SIGPIPE, as `yes | head` does, with
422
+ nothing on stderr. It learns that stdout has no reader only when a write to it fails, so a command that prints nothing
423
+ more runs to its end first (`mcmd 'sleep 4' | head -2` takes 4 s, as `sleep 4 | head -2` does). A program that imports
424
+ multiCMD still gets the `BrokenPipeError`. At interpreter exit
419
425
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
420
426
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
421
427
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -432,10 +438,23 @@ starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C
432
438
  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
433
439
  `kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
434
440
  even one at a few points between the steps of a run can leave its command registered but not signalled.
435
- 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
436
- `threading`'s can hang the program as its threads end (CPython's own), and one of multiCMD's (an
437
- `AsyncExecutor`'s queue, the live output) hangs that executor, or the next call that is not quiet, if the
438
- program keeps going.
441
+ 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
442
+ `threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
443
+ its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
444
+ executor, or the next call that is not quiet, if the program keeps going.
445
+ A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
446
+ included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
447
+ main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
448
+ call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
449
+ 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
450
+ 1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
451
+ 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
452
+ ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
453
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
454
+ about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): the same message, and the next Ctrl-C works. On Python 3.6-3.10 a
455
+ Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen`, normally about 1 ms (2-5 ms at p99); if the
456
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
457
+ answers.
439
458
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
440
459
 
441
460
  ## Key functions and objects
@@ -487,6 +506,81 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
487
506
 
488
507
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
489
508
 
509
+ ## Upgrading to 1.61 from 1.60
510
+
511
+ - Nothing needs doing to upgrade.
512
+ - Fix: `mcmd ... | head` (a reader that quits early) ends quietly. It printed a traceback or an "Exception ignored" message
513
+ and exited 120 (Python's status for a stdout it cannot flush), and the commands were left to run on: a quiet one,
514
+ or one that ignores SIGPIPE, ran to its end or for ever, with `mcmd` waiting for it. Now `mcmd` stops the commands as a
515
+ Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
516
+ Windows, untested: a closed pipe may show there as an `OSError` that `mcmd` does not catch yet, planned for 1.62). It
517
+ covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions still raise
518
+ `BrokenPipeError` when `sys.stdout` fails. A thread that finds stdout closed only says so, and the main thread's
519
+ waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
520
+ `mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
521
+ drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
522
+ the reader quit (`mcmd 'sleep 4' | head -2`, a `-q` run, one under `-t`) runs to its end first, as it did, and then
523
+ `mcmd` ends 141. Planned for 1.62: asking the pipe instead of waiting for a write.
524
+ - Changed: a closed stderr with a working stdout can now end `mcmd` by SIGPIPE (141) when `mcmd` itself prints an error
525
+ there; it ended 120 with 1.60. Measured: on 3.9 and 3.10 an unbalanced quote, a usage error and "no commands given" all
526
+ end 141; on 3.12 and 3.14 only the unbalanced quote does, as argparse's own errors stay 120; on 3.6 nothing changes
527
+ (all 120). The error of a command that cannot run ends as before on every Python.
528
+ - Fix, Python 3.6 to 3.10: a stop (a Ctrl-C, `stop()`, `kill_all(signal.SIGINT)`) that lands as a command starts no
529
+ longer crashes the exec wrapper's Python. A stop sends SIGINT first, and a Python that SIGINT reaches while it
530
+ initializes aborts with a core dump on 3.6 and 3.7 ("Fatal Python error: ... can't initialize sys standard streams")
531
+ and exits 1 with that message on 3.8 to 3.10; a little later in its start it prints a `KeyboardInterrupt` traceback.
532
+ Each landed in that command's stderr, and each core dump in the host's crash handler (systemd-coredump, apport, abrt).
533
+ Aimed at random into 400 starts each with 1.60: 80 aborted on 3.6 (1.59 the same) and 63 on 3.7; 54, 41 and 42 exited
534
+ with "Fatal Python error" on 3.8, 3.9 and 3.10; with 1.61 every one ended by SIGINT or ran to its end, without a
535
+ word. It is not new: every version with the exec wrapper (1.52 on) had it. The wrapper now starts with SIGINT
536
+ blocked and unblocks it once it has the command, so such a stop ends it by SIGINT, as it ends the command; a command
537
+ still inherits SIGINT blocked from a calling thread that has it blocked. On GitHub's runners the core dumps of
538
+ 1.60's new stop test (5,000 stops in one process) each started an apport process, which drove the load to 250 and
539
+ timed the 3.6 job out.
540
+ - Known: on Python 3.6 to 3.10 a Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen` (the fork,
541
+ the exec of the Python binary, the read of its error pipe), normally about 1 ms (2 to 5 ms at p99), where 1.60 stopped
542
+ at once. If the exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), Ctrl-C does
543
+ nothing until the mount answers; 1.60 exited 130. See [docs/limitations.md](docs/limitations.md).
544
+ - Known: a Ctrl-C that lands in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished, in a serial run, is
545
+ dropped (12 of about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): Python prints "Exception ignored" and the run goes
546
+ on; press it again. It is the dropped Ctrl-C of 1.60's note below, in serial runs too. See
547
+ [docs/limitations.md](docs/limitations.md).
548
+
549
+ ## Upgrading to 1.60 from 1.59
550
+
551
+ - Nothing needs doing to upgrade.
552
+ - Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
553
+ Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
554
+ leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
555
+ blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
556
+ program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
557
+ 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.
558
+ - Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
559
+ fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
560
+ thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
561
+ starts the thread exists), see [docs/limitations.md](docs/limitations.md).
562
+ - A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
563
+ `threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
564
+ reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
565
+ its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
566
+ - The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
567
+ dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
568
+ 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
569
+ against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
570
+ 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
571
+ 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
572
+ 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
573
+ for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
574
+ most), so multiCMD knows whether the thread runs.
575
+ - Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
576
+ 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
577
+ there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
578
+ [docs/limitations.md](docs/limitations.md).
579
+ - The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
580
+ `multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
581
+ the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
582
+ pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
583
+
490
584
  ## Upgrading to 1.59 from 1.58
491
585
 
492
586
  - Nothing needs doing to upgrade.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.59
3
+ Version: 1.61
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -119,6 +119,7 @@ exit status:
119
119
  N several commands: how many failed, capped at 101
120
120
  2 usage error
121
121
  130 interrupted with Ctrl-C ( 128+S after SIGTERM / SIGHUP )
122
+ 141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows, untested there )
122
123
  ```
123
124
 
124
125
  ### Examples
@@ -192,6 +193,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
192
193
  | Several commands | the number that failed, capped at `101` |
193
194
  | Usage error (bad option, unbalanced quote, no commands) | `2` |
194
195
  | Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
196
+ | stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows (untested there) |
195
197
 
196
198
  ### Input files and templates
197
199
 
@@ -441,7 +443,11 @@ Signals sent to your program's group do not reach the commands, so multiCMD stop
441
443
  Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main thread, `join_threads()`
442
444
  and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
443
445
  re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
444
- commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`). At interpreter exit
446
+ commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
447
+ has no reader (`mcmd ... | head`): it stops them as a Ctrl-C does, and ends by SIGPIPE, as `yes | head` does, with
448
+ nothing on stderr. It learns that stdout has no reader only when a write to it fails, so a command that prints nothing
449
+ more runs to its end first (`mcmd 'sleep 4' | head -2` takes 4 s, as `sleep 4 | head -2` does). A program that imports
450
+ multiCMD still gets the `BrokenPipeError`. At interpreter exit
445
451
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
446
452
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
447
453
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -458,10 +464,23 @@ starts a command keeps that command from running at all; on 3.11+ such a Ctrl-C
458
464
  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
459
465
  `kill_all()` or the exit stops it. On Python 3.6-3.9, which raise a Ctrl-C at nearly any instruction,
460
466
  even one at a few points between the steps of a run can leave its command registered but not signalled.
461
- 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
462
- `threading`'s can hang the program as its threads end (CPython's own), and one of multiCMD's (an
463
- `AsyncExecutor`'s queue, the live output) hangs that executor, or the next call that is not quiet, if the
464
- program keeps going.
467
+ 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
468
+ `threading`'s, in your program's own code, can hang the program as its threads end (CPython's own; multiCMD starts
469
+ its threads where no handler runs), and one of multiCMD's (an `AsyncExecutor`'s queue, the live output) hangs that
470
+ executor, or the next call that is not quiet, if the program keeps going.
471
+ A Python-level primitive such as `threading.Semaphore` or `Condition` is reached on every Python, 3.10 to 3.13
472
+ included: if your program passes its own `Semaphore` as `sem=` to a serial `run_command()` or `run_commands()` on the
473
+ main thread, and keeps going after it catches a Ctrl-C, the Ctrl-C can lose a permit (with `Semaphore(1)` the next
474
+ call waits for ever) or leave the semaphore's internal lock held (every later `acquire()` or `release()` of it blocks,
475
+ 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
476
+ 1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
477
+ 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
478
+ ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
479
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
480
+ about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): the same message, and the next Ctrl-C works. On Python 3.6-3.10 a
481
+ Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen`, normally about 1 ms (2-5 ms at p99); if the
482
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
483
+ answers.
465
484
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
466
485
 
467
486
  ## Key functions and objects
@@ -513,6 +532,81 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
513
532
 
514
533
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
515
534
 
535
+ ## Upgrading to 1.61 from 1.60
536
+
537
+ - Nothing needs doing to upgrade.
538
+ - Fix: `mcmd ... | head` (a reader that quits early) ends quietly. It printed a traceback or an "Exception ignored" message
539
+ and exited 120 (Python's status for a stdout it cannot flush), and the commands were left to run on: a quiet one,
540
+ or one that ignores SIGPIPE, ran to its end or for ever, with `mcmd` waiting for it. Now `mcmd` stops the commands as a
541
+ Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
542
+ Windows, untested: a closed pipe may show there as an `OSError` that `mcmd` does not catch yet, planned for 1.62). It
543
+ covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions still raise
544
+ `BrokenPipeError` when `sys.stdout` fails. A thread that finds stdout closed only says so, and the main thread's
545
+ waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
546
+ `mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
547
+ drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
548
+ the reader quit (`mcmd 'sleep 4' | head -2`, a `-q` run, one under `-t`) runs to its end first, as it did, and then
549
+ `mcmd` ends 141. Planned for 1.62: asking the pipe instead of waiting for a write.
550
+ - Changed: a closed stderr with a working stdout can now end `mcmd` by SIGPIPE (141) when `mcmd` itself prints an error
551
+ there; it ended 120 with 1.60. Measured: on 3.9 and 3.10 an unbalanced quote, a usage error and "no commands given" all
552
+ end 141; on 3.12 and 3.14 only the unbalanced quote does, as argparse's own errors stay 120; on 3.6 nothing changes
553
+ (all 120). The error of a command that cannot run ends as before on every Python.
554
+ - Fix, Python 3.6 to 3.10: a stop (a Ctrl-C, `stop()`, `kill_all(signal.SIGINT)`) that lands as a command starts no
555
+ longer crashes the exec wrapper's Python. A stop sends SIGINT first, and a Python that SIGINT reaches while it
556
+ initializes aborts with a core dump on 3.6 and 3.7 ("Fatal Python error: ... can't initialize sys standard streams")
557
+ and exits 1 with that message on 3.8 to 3.10; a little later in its start it prints a `KeyboardInterrupt` traceback.
558
+ Each landed in that command's stderr, and each core dump in the host's crash handler (systemd-coredump, apport, abrt).
559
+ Aimed at random into 400 starts each with 1.60: 80 aborted on 3.6 (1.59 the same) and 63 on 3.7; 54, 41 and 42 exited
560
+ with "Fatal Python error" on 3.8, 3.9 and 3.10; with 1.61 every one ended by SIGINT or ran to its end, without a
561
+ word. It is not new: every version with the exec wrapper (1.52 on) had it. The wrapper now starts with SIGINT
562
+ blocked and unblocks it once it has the command, so such a stop ends it by SIGINT, as it ends the command; a command
563
+ still inherits SIGINT blocked from a calling thread that has it blocked. On GitHub's runners the core dumps of
564
+ 1.60's new stop test (5,000 stops in one process) each started an apport process, which drove the load to 250 and
565
+ timed the 3.6 job out.
566
+ - Known: on Python 3.6 to 3.10 a Ctrl-C that arrives as a command starts waits for the exec wrapper's `Popen` (the fork,
567
+ the exec of the Python binary, the read of its error pipe), normally about 1 ms (2 to 5 ms at p99), where 1.60 stopped
568
+ at once. If the exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), Ctrl-C does
569
+ nothing until the mount answers; 1.60 exited 130. See [docs/limitations.md](docs/limitations.md).
570
+ - Known: a Ctrl-C that lands in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished, in a serial run, is
571
+ dropped (12 of about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): Python prints "Exception ignored" and the run goes
572
+ on; press it again. It is the dropped Ctrl-C of 1.60's note below, in serial runs too. See
573
+ [docs/limitations.md](docs/limitations.md).
574
+
575
+ ## Upgrading to 1.60 from 1.59
576
+
577
+ - Nothing needs doing to upgrade.
578
+ - Fix: a Ctrl-C, or what your own signal handler raises, can no longer hang the program in Python's thread-start lock.
579
+ Python runs signal handlers on the main thread, and one that raised inside `threading.Thread.start()` there could
580
+ leave `threading`'s `_active_limbo_lock`, or the new thread's `_started` Event, held: every later thread start then
581
+ blocked, and on Python 3.6 the exit too. A serial run starts two output readers per command on the main thread, so a
582
+ program stopped often met it: a probe that stops a serial `run_command(['true'])` at random, 20,000 times in one
583
+ 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.
584
+ - Fix: what your own signal handler raises (an ordinary exception, a `TimeoutError` from SIGALRM) while a pool or a
585
+ fire-and-forget batch starts its threads is raised as an interrupt, every command stopped. Before, it was taken for a
586
+ thread that could not start, and lost. A few microseconds of each start remain (about 4 µs, before the helper that
587
+ starts the thread exists), see [docs/limitations.md](docs/limitations.md).
588
+ - A command's output readers are now threads started with `_thread.start_new_thread`: they are not in
589
+ `threading.enumerate()` or `threading.active_count()`, `threading.settrace()`, `setprofile()` and `excepthook` do not
590
+ reach them, and an error in one is reported through `sys.unraisablehook` (from Python 3.8). A serial run is no slower:
591
+ its median was 0 to 4 % below 1.59's, timed side by side on 3.6, 3.12 and 3.14.
592
+ - The threads multiCMD starts on the main thread (a pool's workers, fire-and-forget commands, an `AsyncExecutor`'s
593
+ dispatcher) start through a helper thread, so no signal handler runs inside `threading`'s start: about 20 µs more per
594
+ 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
595
+ against 34 µs on a host loaded past its cores). In a batch whose first commands already run, each hand-off to the
596
+ 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
597
+ 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
598
+ 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
599
+ for `threading`'s start. A Ctrl-C that lands while such a thread starts is raised once the start is done (1 s at
600
+ most), so multiCMD knows whether the thread runs.
601
+ - Known: in the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C is dropped about
602
+ 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
603
+ there): Python prints "Exception ignored" and the program goes on, and the next Ctrl-C works. See
604
+ [docs/limitations.md](docs/limitations.md).
605
+ - The embeddable copy for programs that paste multiCMD is now `multiCMD_min_zlib_a85.py`, in place of
606
+ `multiCMD_min_lzma_a85.py`. It decodes with zlib, so it runs on a Python built without lzma, where the lzma one made
607
+ the program fail to import unless its installed multiCMD was new enough. It is about 7 % larger. Its block may be
608
+ pasted indented inside a `try`: ascii85 decoding ignores the added tabs.
609
+
516
610
  ## Upgrading to 1.59 from 1.58
517
611
 
518
612
  - Nothing needs doing to upgrade.
@@ -11,9 +11,11 @@ scripts/multiCMD
11
11
  tests/test_api.py
12
12
  tests/test_async_executor.py
13
13
  tests/test_cli.py
14
+ tests/test_cli_closed_stdout.py
14
15
  tests/test_cli_input.py
15
16
  tests/test_cli_summary.py
16
17
  tests/test_display.py
18
+ tests/test_embed.py
17
19
  tests/test_env.py
18
20
  tests/test_expand_ranges.py
19
21
  tests/test_handover.py