multiCMD 1.60__tar.gz → 1.62__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.60 → multicmd-1.62}/PKG-INFO +79 -3
  2. {multicmd-1.60 → multicmd-1.62}/README.md +78 -2
  3. {multicmd-1.60 → multicmd-1.62}/multiCMD.egg-info/PKG-INFO +79 -3
  4. {multicmd-1.60 → multicmd-1.62}/multiCMD.egg-info/SOURCES.txt +1 -0
  5. {multicmd-1.60 → multicmd-1.62}/multiCMD.py +225 -23
  6. multicmd-1.62/tests/test_cli_closed_stdout.py +725 -0
  7. {multicmd-1.60 → multicmd-1.62}/tests/test_display.py +48 -0
  8. {multicmd-1.60 → multicmd-1.62}/tests/test_handover.py +38 -0
  9. {multicmd-1.60 → multicmd-1.62}/tests/test_helpers.py +40 -0
  10. {multicmd-1.60 → multicmd-1.62}/tests/test_process_groups.py +27 -1
  11. {multicmd-1.60 → multicmd-1.62}/LICENSE +0 -0
  12. {multicmd-1.60 → multicmd-1.62}/multiCMD.egg-info/dependency_links.txt +0 -0
  13. {multicmd-1.60 → multicmd-1.62}/multiCMD.egg-info/entry_points.txt +0 -0
  14. {multicmd-1.60 → multicmd-1.62}/multiCMD.egg-info/top_level.txt +0 -0
  15. {multicmd-1.60 → multicmd-1.62}/scripts/multiCMD +0 -0
  16. {multicmd-1.60 → multicmd-1.62}/setup.cfg +0 -0
  17. {multicmd-1.60 → multicmd-1.62}/setup.py +0 -0
  18. {multicmd-1.60 → multicmd-1.62}/tests/test_api.py +0 -0
  19. {multicmd-1.60 → multicmd-1.62}/tests/test_async_executor.py +0 -0
  20. {multicmd-1.60 → multicmd-1.62}/tests/test_cli.py +0 -0
  21. {multicmd-1.60 → multicmd-1.62}/tests/test_cli_input.py +0 -0
  22. {multicmd-1.60 → multicmd-1.62}/tests/test_cli_summary.py +0 -0
  23. {multicmd-1.60 → multicmd-1.62}/tests/test_embed.py +0 -0
  24. {multicmd-1.60 → multicmd-1.62}/tests/test_env.py +0 -0
  25. {multicmd-1.60 → multicmd-1.62}/tests/test_expand_ranges.py +0 -0
  26. {multicmd-1.60 → multicmd-1.62}/tests/test_interrupts.py +0 -0
  27. {multicmd-1.60 → multicmd-1.62}/tests/test_packaging.py +0 -0
  28. {multicmd-1.60 → multicmd-1.62}/tests/test_parsing.py +0 -0
  29. {multicmd-1.60 → multicmd-1.62}/tests/test_pass_fds.py +0 -0
  30. {multicmd-1.60 → multicmd-1.62}/tests/test_ping.py +0 -0
  31. {multicmd-1.60 → multicmd-1.62}/tests/test_pool.py +0 -0
  32. {multicmd-1.60 → multicmd-1.62}/tests/test_pty.py +0 -0
  33. {multicmd-1.60 → multicmd-1.62}/tests/test_reader.py +0 -0
  34. {multicmd-1.60 → multicmd-1.62}/tests/test_regressions.py +0 -0
  35. {multicmd-1.60 → multicmd-1.62}/tests/test_run_command.py +0 -0
  36. {multicmd-1.60 → multicmd-1.62}/tests/test_run_commands.py +0 -0
  37. {multicmd-1.60 → multicmd-1.62}/tests/test_sudo.py +0 -0
  38. {multicmd-1.60 → multicmd-1.62}/tests/test_supervision.py +0 -0
  39. {multicmd-1.60 → multicmd-1.62}/tests/test_task.py +0 -0
  40. {multicmd-1.60 → multicmd-1.62}/tests/test_windows.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.60
3
+ Version: 1.62
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 )
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 |
195
197
 
196
198
  ### Input files and templates
197
199
 
@@ -441,7 +443,16 @@ 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. When stdout is a pipe on Linux and macOS it also asks the pipe as it waits, so a command that prints
449
+ nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
450
+ learns it only when a write fails, and a command that prints nothing more runs to its end first. ksh93 on Linux builds its
451
+ pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
452
+ mksh, busybox and macOS's ksh give a pipe). A run that must outlive whatever reads its stdout (a terminal that hangs up, or
453
+ under `nohup` or over `ssh`, where `nohup` leaves a stdout that is not a terminal alone) needs its stdout sent to a file or
454
+ `/dev/null`: `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD still gets the
455
+ write's error (`BrokenPipeError`; `OSError` EINVAL on Windows). At interpreter exit
445
456
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
446
457
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
447
458
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -470,7 +481,11 @@ on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2
470
481
  1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
471
482
  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
483
  ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
473
- Ctrl-C works.
484
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
485
+ 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
486
+ 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
487
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
488
+ answers.
474
489
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
475
490
 
476
491
  ## Key functions and objects
@@ -522,6 +537,67 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
522
537
 
523
538
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
524
539
 
540
+ ## Upgrading to 1.62 from 1.61
541
+
542
+ - Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
543
+ `ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
544
+ now stops when that pipe's reader quits, where 1.61 ran it to its end. Send its stdout to a file or `/dev/null`:
545
+ `nohup mcmd -q "job" > log 2>&1 &`.
546
+ - Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
547
+ waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
548
+ a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
549
+ commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
550
+ and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
551
+ - Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
552
+ Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
553
+ from each reader and exited 120 (seen on GitHub's windows-latest with Python 3.9, 3.12 and 3.14, in Git Bash and cmd pipes;
554
+ once 127 with "Fatal Python error" on 3.14). `mcmd` takes EINVAL from a write to any stdout, not only a pipe, as a reader
555
+ that quit. The library's functions treat that `OSError` as 1.61 did.
556
+ - Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
557
+ C locale, whose stdout is ASCII: hpcp's progress line), or a file name in its prefix (one that is not valid UTF-8, on a
558
+ UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
559
+ same in 1.59 to 1.61.
560
+
561
+ ## Upgrading to 1.61 from 1.60
562
+
563
+ - Nothing needs doing to upgrade.
564
+ - Fix: `mcmd ... | head` (a reader that quits early) ends quietly. It printed a traceback or an "Exception ignored" message
565
+ and exited 120 (Python's status for a stdout it cannot flush), and the commands were left to run on: a quiet one,
566
+ or one that ignores SIGPIPE, ran to its end or for ever, with `mcmd` waiting for it. Now `mcmd` stops the commands as a
567
+ Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
568
+ Windows, untested: a closed pipe may show there as an `OSError` that `mcmd` does not catch yet, planned for 1.62). It
569
+ covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions treat a
570
+ `BrokenPipeError` from `sys.stdout` as 1.60 did. A thread that finds stdout closed only says so, and the main thread's
571
+ waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
572
+ `mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
573
+ drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
574
+ the reader quit (`mcmd 'sleep 4' | head -2`, a `-q` run, one under `-t`) runs to its end first, as it did, and then
575
+ `mcmd` ends 141. Planned for 1.62: asking the pipe instead of waiting for a write.
576
+ - Changed: a closed stderr with a working stdout can now end `mcmd` by SIGPIPE (141) when `mcmd` itself prints an error
577
+ 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
578
+ 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
579
+ (all 120). The error of a command that cannot run ends as before on every Python.
580
+ - Fix, Python 3.6 to 3.10: a stop (a Ctrl-C, `stop()`, `kill_all(signal.SIGINT)`) that lands as a command starts no
581
+ longer crashes the exec wrapper's Python. A stop sends SIGINT first, and a Python that SIGINT reaches while it
582
+ initializes aborts with a core dump on 3.6 and 3.7 ("Fatal Python error: ... can't initialize sys standard streams")
583
+ and exits 1 with that message on 3.8 to 3.10; a little later in its start it prints a `KeyboardInterrupt` traceback.
584
+ Each landed in that command's stderr, and each core dump in the host's crash handler (systemd-coredump, apport, abrt).
585
+ 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
586
+ 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
587
+ word. It is not new: every version with the exec wrapper (1.52 on) had it. The wrapper now starts with SIGINT
588
+ blocked and unblocks it once it has the command, so such a stop ends it by SIGINT, as it ends the command; a command
589
+ still inherits SIGINT blocked from a calling thread that has it blocked. On GitHub's runners the core dumps of
590
+ 1.60's new stop test (5,000 stops in one process) each started an apport process, which drove the load to 250 and
591
+ timed the 3.6 job out.
592
+ - 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,
593
+ 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
594
+ at once. If the exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), Ctrl-C does
595
+ nothing until the mount answers; 1.60 exited 130. See [docs/limitations.md](docs/limitations.md).
596
+ - Known: a Ctrl-C that lands in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished, in a serial run, is
597
+ dropped (12 of about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): Python prints "Exception ignored" and the run goes
598
+ on; press it again. It is the dropped Ctrl-C of 1.60's note below, in serial runs too. See
599
+ [docs/limitations.md](docs/limitations.md).
600
+
525
601
  ## Upgrading to 1.60 from 1.59
526
602
 
527
603
  - 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 )
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 |
169
171
 
170
172
  ### Input files and templates
171
173
 
@@ -415,7 +417,16 @@ 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. When stdout is a pipe on Linux and macOS it also asks the pipe as it waits, so a command that prints
423
+ nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
424
+ learns it only when a write fails, and a command that prints nothing more runs to its end first. ksh93 on Linux builds its
425
+ pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
426
+ mksh, busybox and macOS's ksh give a pipe). A run that must outlive whatever reads its stdout (a terminal that hangs up, or
427
+ under `nohup` or over `ssh`, where `nohup` leaves a stdout that is not a terminal alone) needs its stdout sent to a file or
428
+ `/dev/null`: `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD still gets the
429
+ write's error (`BrokenPipeError`; `OSError` EINVAL on Windows). At interpreter exit
419
430
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
420
431
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
421
432
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -444,7 +455,11 @@ on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2
444
455
  1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
445
456
  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
457
  ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
447
- Ctrl-C works.
458
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
459
+ 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
460
+ 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
461
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
462
+ answers.
448
463
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
449
464
 
450
465
  ## Key functions and objects
@@ -496,6 +511,67 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
496
511
 
497
512
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
498
513
 
514
+ ## Upgrading to 1.62 from 1.61
515
+
516
+ - Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
517
+ `ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
518
+ now stops when that pipe's reader quits, where 1.61 ran it to its end. Send its stdout to a file or `/dev/null`:
519
+ `nohup mcmd -q "job" > log 2>&1 &`.
520
+ - Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
521
+ waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
522
+ a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
523
+ commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
524
+ and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
525
+ - Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
526
+ Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
527
+ from each reader and exited 120 (seen on GitHub's windows-latest with Python 3.9, 3.12 and 3.14, in Git Bash and cmd pipes;
528
+ once 127 with "Fatal Python error" on 3.14). `mcmd` takes EINVAL from a write to any stdout, not only a pipe, as a reader
529
+ that quit. The library's functions treat that `OSError` as 1.61 did.
530
+ - Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
531
+ C locale, whose stdout is ASCII: hpcp's progress line), or a file name in its prefix (one that is not valid UTF-8, on a
532
+ UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
533
+ same in 1.59 to 1.61.
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 treat a
544
+ `BrokenPipeError` from `sys.stdout` as 1.60 did. 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
+
499
575
  ## Upgrading to 1.60 from 1.59
500
576
 
501
577
  - Nothing needs doing to upgrade.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.60
3
+ Version: 1.62
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 )
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 |
195
197
 
196
198
  ### Input files and templates
197
199
 
@@ -441,7 +443,16 @@ 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. When stdout is a pipe on Linux and macOS it also asks the pipe as it waits, so a command that prints
449
+ nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
450
+ learns it only when a write fails, and a command that prints nothing more runs to its end first. ksh93 on Linux builds its
451
+ pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
452
+ mksh, busybox and macOS's ksh give a pipe). A run that must outlive whatever reads its stdout (a terminal that hangs up, or
453
+ under `nohup` or over `ssh`, where `nohup` leaves a stdout that is not a terminal alone) needs its stdout sent to a file or
454
+ `/dev/null`: `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD still gets the
455
+ write's error (`BrokenPipeError`; `OSError` EINVAL on Windows). At interpreter exit
445
456
  the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
446
457
  "not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
447
458
  handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
@@ -470,7 +481,11 @@ on any thread). Measured at 0.02 to 0.42 % of the Ctrl-Cs that land during a 0.2
470
481
  1.59. In the first milliseconds of a fire-and-forget batch (`wait_for_return=False`) a first Ctrl-C can also be
471
482
  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
483
  ignores an exception raised in a weakref callback and prints "Exception ignored", the program goes on, and the next
473
- Ctrl-C works.
484
+ Ctrl-C works. A serial run can drop one too, in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished (12 of
485
+ 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
486
+ 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
487
+ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), it does nothing until the mount
488
+ answers.
474
489
  These and the other known limits are in [docs/limitations.md](docs/limitations.md).
475
490
 
476
491
  ## Key functions and objects
@@ -522,6 +537,67 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
522
537
 
523
538
  `test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
524
539
 
540
+ ## Upgrading to 1.62 from 1.61
541
+
542
+ - Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
543
+ `ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
544
+ now stops when that pipe's reader quits, where 1.61 ran it to its end. Send its stdout to a file or `/dev/null`:
545
+ `nohup mcmd -q "job" > log 2>&1 &`.
546
+ - Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
547
+ waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
548
+ a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
549
+ commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
550
+ and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
551
+ - Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
552
+ Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
553
+ from each reader and exited 120 (seen on GitHub's windows-latest with Python 3.9, 3.12 and 3.14, in Git Bash and cmd pipes;
554
+ once 127 with "Fatal Python error" on 3.14). `mcmd` takes EINVAL from a write to any stdout, not only a pipe, as a reader
555
+ that quit. The library's functions treat that `OSError` as 1.61 did.
556
+ - Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
557
+ C locale, whose stdout is ASCII: hpcp's progress line), or a file name in its prefix (one that is not valid UTF-8, on a
558
+ UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
559
+ same in 1.59 to 1.61.
560
+
561
+ ## Upgrading to 1.61 from 1.60
562
+
563
+ - Nothing needs doing to upgrade.
564
+ - Fix: `mcmd ... | head` (a reader that quits early) ends quietly. It printed a traceback or an "Exception ignored" message
565
+ and exited 120 (Python's status for a stdout it cannot flush), and the commands were left to run on: a quiet one,
566
+ or one that ignores SIGPIPE, ran to its end or for ever, with `mcmd` waiting for it. Now `mcmd` stops the commands as a
567
+ Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
568
+ Windows, untested: a closed pipe may show there as an `OSError` that `mcmd` does not catch yet, planned for 1.62). It
569
+ covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions treat a
570
+ `BrokenPipeError` from `sys.stdout` as 1.60 did. A thread that finds stdout closed only says so, and the main thread's
571
+ waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
572
+ `mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
573
+ drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
574
+ the reader quit (`mcmd 'sleep 4' | head -2`, a `-q` run, one under `-t`) runs to its end first, as it did, and then
575
+ `mcmd` ends 141. Planned for 1.62: asking the pipe instead of waiting for a write.
576
+ - Changed: a closed stderr with a working stdout can now end `mcmd` by SIGPIPE (141) when `mcmd` itself prints an error
577
+ 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
578
+ 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
579
+ (all 120). The error of a command that cannot run ends as before on every Python.
580
+ - Fix, Python 3.6 to 3.10: a stop (a Ctrl-C, `stop()`, `kill_all(signal.SIGINT)`) that lands as a command starts no
581
+ longer crashes the exec wrapper's Python. A stop sends SIGINT first, and a Python that SIGINT reaches while it
582
+ initializes aborts with a core dump on 3.6 and 3.7 ("Fatal Python error: ... can't initialize sys standard streams")
583
+ and exits 1 with that message on 3.8 to 3.10; a little later in its start it prints a `KeyboardInterrupt` traceback.
584
+ Each landed in that command's stderr, and each core dump in the host's crash handler (systemd-coredump, apport, abrt).
585
+ 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
586
+ 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
587
+ word. It is not new: every version with the exec wrapper (1.52 on) had it. The wrapper now starts with SIGINT
588
+ blocked and unblocks it once it has the command, so such a stop ends it by SIGINT, as it ends the command; a command
589
+ still inherits SIGINT blocked from a calling thread that has it blocked. On GitHub's runners the core dumps of
590
+ 1.60's new stop test (5,000 stops in one process) each started an apport process, which drove the load to 250 and
591
+ timed the 3.6 job out.
592
+ - 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,
593
+ 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
594
+ at once. If the exec of the Python binary itself hangs (a venv on an NFS mount that stopped answering), Ctrl-C does
595
+ nothing until the mount answers; 1.60 exited 130. See [docs/limitations.md](docs/limitations.md).
596
+ - Known: a Ctrl-C that lands in `Popen`'s cleanup (`Popen.__del__`) of a command that has finished, in a serial run, is
597
+ dropped (12 of about 6,000 aimed Ctrl-Cs with 1.60, 3 with 1.61): Python prints "Exception ignored" and the run goes
598
+ on; press it again. It is the dropped Ctrl-C of 1.60's note below, in serial runs too. See
599
+ [docs/limitations.md](docs/limitations.md).
600
+
525
601
  ## Upgrading to 1.60 from 1.59
526
602
 
527
603
  - Nothing needs doing to upgrade.
@@ -11,6 +11,7 @@ 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