multiCMD 1.61__tar.gz → 1.63__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.61 → multicmd-1.63}/PKG-INFO +132 -11
- {multicmd-1.61 → multicmd-1.63}/README.md +131 -10
- {multicmd-1.61 → multicmd-1.63}/multiCMD.egg-info/PKG-INFO +132 -11
- {multicmd-1.61 → multicmd-1.63}/multiCMD.egg-info/SOURCES.txt +2 -0
- {multicmd-1.61 → multicmd-1.63}/multiCMD.py +261 -105
- {multicmd-1.61 → multicmd-1.63}/tests/test_cli_closed_stdout.py +350 -19
- multicmd-1.63/tests/test_cli_failed_stdout.py +485 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_display.py +75 -29
- {multicmd-1.61 → multicmd-1.63}/tests/test_helpers.py +40 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_interrupts.py +4 -1
- multicmd-1.63/tests/test_reader_quit.py +274 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_supervision.py +2 -2
- {multicmd-1.61 → multicmd-1.63}/LICENSE +0 -0
- {multicmd-1.61 → multicmd-1.63}/multiCMD.egg-info/dependency_links.txt +0 -0
- {multicmd-1.61 → multicmd-1.63}/multiCMD.egg-info/entry_points.txt +0 -0
- {multicmd-1.61 → multicmd-1.63}/multiCMD.egg-info/top_level.txt +0 -0
- {multicmd-1.61 → multicmd-1.63}/scripts/multiCMD +0 -0
- {multicmd-1.61 → multicmd-1.63}/setup.cfg +0 -0
- {multicmd-1.61 → multicmd-1.63}/setup.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_api.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_async_executor.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_cli.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_cli_input.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_cli_summary.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_embed.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_env.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_expand_ranges.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_handover.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_packaging.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_parsing.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_pass_fds.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_ping.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_pool.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_process_groups.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_pty.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_reader.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_regressions.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_run_command.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_run_commands.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_sudo.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/tests/test_task.py +0 -0
- {multicmd-1.61 → multicmd-1.63}/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.63
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -119,7 +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
|
+
141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows )
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
### Examples
|
|
@@ -193,7 +193,8 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
193
193
|
| Several commands | the number that failed, capped at `101` |
|
|
194
194
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
195
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
|
|
196
|
+
| stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows |
|
|
197
|
+
| stdout fails otherwise (a full disk; a terminal that hung up, on a job its hang-up does not signal) | the commands' own status, as if it had not: every command runs, and one line on stderr says the output was lost (unless stderr is the same dead target, as with `> log 2>&1` on a full disk: then the log just stops) |
|
|
197
198
|
|
|
198
199
|
### Input files and templates
|
|
199
200
|
|
|
@@ -444,10 +445,53 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
444
445
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
445
446
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
446
447
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
447
|
-
has no reader (`mcmd ... | head
|
|
448
|
-
nothing on stderr.
|
|
449
|
-
more
|
|
450
|
-
|
|
448
|
+
has no reader (`mcmd ... | head`, or a socket its peer closed or reset): it stops them as a Ctrl-C does, and ends by
|
|
449
|
+
SIGPIPE, as `yes | head` does, with 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
|
|
450
|
+
nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
|
|
451
|
+
learns it only when a write fails, and a command that prints nothing more runs to its end first (on Windows that is a known
|
|
452
|
+
limitation, docs/limitations.md). ksh93 on Linux builds its
|
|
453
|
+
pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
|
|
454
|
+
mksh, busybox and macOS's ksh give a pipe). A write to stdout that fails for any other reason (EIO from a terminal that
|
|
455
|
+
hung up, ENOSPC from a full disk; on Windows, EINVAL from anything but a pipe) loses only the output: `mcmd` drops it from
|
|
456
|
+
then on, runs every command, running and queued, says so in one line on stderr (`mcmd: cannot write to stdout ([Errno 5]
|
|
457
|
+
Input/output error): its output is dropped from here on`), if stderr can still take it, and exits with the commands' own
|
|
458
|
+
status, also with stdout and stderr on the same file. If stderr is that same dead target (`> log 2>&1` on a full disk), the
|
|
459
|
+
line is lost with the rest and the log just stops (it is written at exit if the target can take it by then). A stdout that
|
|
460
|
+
another program left non-blocking (`O_NONBLOCK`) fails with EAGAIN whenever its pipe or terminal is momentarily full, and
|
|
461
|
+
that counts as a failed write too: the output is dropped from then on. A program that imports multiCMD then never learns that
|
|
462
|
+
its reader quit: a shown `tail -f` runs on after `prog | head` has quit (`mcmd` asks the pipe, as above, and stops; see
|
|
463
|
+
docs/limitations.md). A terminal that hangs up also sends SIGHUP to the job in its foreground (a closed terminal window, or `ssh -t` whose connection drops), and bash and
|
|
464
|
+
zsh pass it on to every job they started, in the background too (dash does not): that stops the commands as before, and
|
|
465
|
+
`mcmd` ends `129`. A job nobody signals runs to its end: one that was `disown`ed, started with `setsid` or `nohup`, or, in
|
|
466
|
+
bash and dash, left in the background by `exit` (zsh signals its jobs on `exit` too). Over `ssh` without a pty, stdout is a
|
|
467
|
+
pipe to sshd, and a dropped connection closes it: a reader that quit. So a run that must outlive its terminal or its
|
|
468
|
+
connection, whatever starts it, runs under `nohup` (against the hang-up's SIGHUP) with its stdout in a file (which no
|
|
469
|
+
hang-up or dropped connection can close): `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD follows the same
|
|
470
|
+
rule for the writes of multiCMD's own output (its live output, `print_progress_bar()`, the report of `AsyncExecutor.join()`),
|
|
471
|
+
and none of those writes raises an `OSError` in the thread that wrote (a `sys.stdout` the program closed itself still gives
|
|
472
|
+
`ValueError`, as in 1.62: deferred to 1.64, docs/limitations.md). A reader that quit (`BrokenPipeError`, `ConnectionResetError`, or on
|
|
473
|
+
Windows `OSError` EINVAL from a pipe) stops the calls that are showing their commands (not quiet): their commands are
|
|
474
|
+
stopped as a Ctrl-C stops them, the queued ones are skipped (return code `None`), and a call that waits raises
|
|
475
|
+
`BrokenPipeError` once its commands are dead, whichever of those forms the platform gave the write (`except OSError` catches
|
|
476
|
+
it too). A pool stops all its commands, and a call on a thread of the program's own raises in that thread. Shown commands
|
|
477
|
+
nobody waits for (an `AsyncExecutor` made with `quiet=False`, `run_commands(wait_for_return=False)`; an `AsyncExecutor` is
|
|
478
|
+
quiet by default, and a quiet one is never stopped) are stopped without an error: `wait()`, `join()` and `join_threads()`
|
|
479
|
+
return, and the tasks tell (a stopped one has the kill's return code, a queued one `None`). Every call made after multiCMD
|
|
480
|
+
has found the reader gone, for the rest of the process, runs its commands unseen, and multiCMD's own stderr lines for it
|
|
481
|
+
(`Command path not found`, `Error running command`) are not printed either. So a cleanup in a `finally` (an unmount) runs
|
|
482
|
+
once an earlier shown call has raised. A call whose own first lines meet the reader quitting, or that follows only the
|
|
483
|
+
program's own write to that closed pipe, is a shown call like any other: its commands are skipped, and a call that waits raises. A cleanup that must run
|
|
484
|
+
whatever stdout does passes `quiet=True`. A quiet call never looks at stdout. One edge of the rule for calls made after the reader quit (deferred to 1.64,
|
|
485
|
+
docs/limitations.md): a shown call that starts after multiCMD has found the reader gone runs its commands unseen to their end,
|
|
486
|
+
on any thread, so a program that fans shown calls out over its own threads (a thread pool) under `prog | head` keeps running
|
|
487
|
+
as long as a remaining call's command runs (for ever, with `tail -f`); run such a fan-out as one call with `max_threads`, which stops as one. The library learns that its reader quit only from a failed write, and does not poll the pipe as `mcmd` does, so a
|
|
488
|
+
shown command that prints nothing more (`tail -f` of a log that went idle, under `prog | head -1`) runs until its next line
|
|
489
|
+
(see docs/limitations.md). Any other failed write (EIO from a terminal that hung up, ENOSPC from a full disk) loses only the
|
|
490
|
+
output: multiCMD's output is dropped from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and
|
|
491
|
+
every command runs. The program's own writes to that stdout meet the error themselves, and so does Python's flush at exit,
|
|
492
|
+
which still finds what the failed write left in `sys.stdout`'s buffer: unless the program handles that, it ends with
|
|
493
|
+
"Exception ignored" and status 120, as after a failed print of its own (a library does not redirect its caller's stdout).
|
|
494
|
+
At interpreter exit
|
|
451
495
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
452
496
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
453
497
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -455,8 +499,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
455
499
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
456
500
|
stderr, unless quiet.
|
|
457
501
|
|
|
458
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
459
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
502
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
503
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
460
504
|
|
|
461
505
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
462
506
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -532,6 +576,83 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
532
576
|
|
|
533
577
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
534
578
|
|
|
579
|
+
## Upgrading to 1.63 from 1.62
|
|
580
|
+
|
|
581
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
582
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
583
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
584
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
585
|
+
disk, a terminal that hung up) no longer gets it: the commands run, and one line on stderr says the output is dropped (1.62
|
|
586
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
587
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
588
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
589
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
590
|
+
so none blocks), says so in one line on stderr, if stderr can still take it (not with `> log 2>&1` on that disk: the log
|
|
591
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
592
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
593
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
594
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
595
|
+
(`129`), as before.
|
|
596
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
597
|
+
are dropped. 1.62 ended 120, from Python's flush at exit (`mcmd no-such-command 2>/dev/full` gave 120, not 127). On Python
|
|
598
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
599
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
600
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
601
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
602
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
603
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
604
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
605
|
+
running command" and did not run it (return code -1).
|
|
606
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
607
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
608
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
609
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
610
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
611
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
612
|
+
write errors too).
|
|
613
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
614
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
615
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
616
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
617
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
618
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
619
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
620
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
621
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
622
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
623
|
+
thread, so a fan-out over the program's own threads (a thread pool) under `prog | head` can keep running as long as a remaining
|
|
624
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
625
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
626
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
627
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
628
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
629
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
630
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
631
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
632
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
633
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
634
|
+
|
|
635
|
+
## Upgrading to 1.62 from 1.61
|
|
636
|
+
|
|
637
|
+
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
638
|
+
`ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
|
|
639
|
+
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`:
|
|
640
|
+
`nohup mcmd -q "job" > log 2>&1 &`.
|
|
641
|
+
- Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
|
|
642
|
+
waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
|
|
643
|
+
a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
|
|
644
|
+
commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
|
|
645
|
+
and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
|
|
646
|
+
- Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
|
|
647
|
+
Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
|
|
648
|
+
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;
|
|
649
|
+
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
|
|
650
|
+
that quit. The library's functions treat that `OSError` as 1.61 did.
|
|
651
|
+
- Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
|
|
652
|
+
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
|
|
653
|
+
UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
|
|
654
|
+
same in 1.59 to 1.61.
|
|
655
|
+
|
|
535
656
|
## Upgrading to 1.61 from 1.60
|
|
536
657
|
|
|
537
658
|
- Nothing needs doing to upgrade.
|
|
@@ -540,8 +661,8 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
540
661
|
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
662
|
Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
|
|
542
663
|
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
|
|
544
|
-
`BrokenPipeError`
|
|
664
|
+
covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions treat a
|
|
665
|
+
`BrokenPipeError` from `sys.stdout` as 1.60 did. A thread that finds stdout closed only says so, and the main thread's
|
|
545
666
|
waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
|
|
546
667
|
`mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
|
|
547
668
|
drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
|
|
@@ -93,7 +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
|
+
141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows )
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
### Examples
|
|
@@ -167,7 +167,8 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
167
167
|
| Several commands | the number that failed, capped at `101` |
|
|
168
168
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
169
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
|
|
170
|
+
| stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows |
|
|
171
|
+
| stdout fails otherwise (a full disk; a terminal that hung up, on a job its hang-up does not signal) | the commands' own status, as if it had not: every command runs, and one line on stderr says the output was lost (unless stderr is the same dead target, as with `> log 2>&1` on a full disk: then the log just stops) |
|
|
171
172
|
|
|
172
173
|
### Input files and templates
|
|
173
174
|
|
|
@@ -418,10 +419,53 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
418
419
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
419
420
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
420
421
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
421
|
-
has no reader (`mcmd ... | head
|
|
422
|
-
nothing on stderr.
|
|
423
|
-
more
|
|
424
|
-
|
|
422
|
+
has no reader (`mcmd ... | head`, or a socket its peer closed or reset): it stops them as a Ctrl-C does, and ends by
|
|
423
|
+
SIGPIPE, as `yes | head` does, with 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
|
|
424
|
+
nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
|
|
425
|
+
learns it only when a write fails, and a command that prints nothing more runs to its end first (on Windows that is a known
|
|
426
|
+
limitation, docs/limitations.md). ksh93 on Linux builds its
|
|
427
|
+
pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
|
|
428
|
+
mksh, busybox and macOS's ksh give a pipe). A write to stdout that fails for any other reason (EIO from a terminal that
|
|
429
|
+
hung up, ENOSPC from a full disk; on Windows, EINVAL from anything but a pipe) loses only the output: `mcmd` drops it from
|
|
430
|
+
then on, runs every command, running and queued, says so in one line on stderr (`mcmd: cannot write to stdout ([Errno 5]
|
|
431
|
+
Input/output error): its output is dropped from here on`), if stderr can still take it, and exits with the commands' own
|
|
432
|
+
status, also with stdout and stderr on the same file. If stderr is that same dead target (`> log 2>&1` on a full disk), the
|
|
433
|
+
line is lost with the rest and the log just stops (it is written at exit if the target can take it by then). A stdout that
|
|
434
|
+
another program left non-blocking (`O_NONBLOCK`) fails with EAGAIN whenever its pipe or terminal is momentarily full, and
|
|
435
|
+
that counts as a failed write too: the output is dropped from then on. A program that imports multiCMD then never learns that
|
|
436
|
+
its reader quit: a shown `tail -f` runs on after `prog | head` has quit (`mcmd` asks the pipe, as above, and stops; see
|
|
437
|
+
docs/limitations.md). A terminal that hangs up also sends SIGHUP to the job in its foreground (a closed terminal window, or `ssh -t` whose connection drops), and bash and
|
|
438
|
+
zsh pass it on to every job they started, in the background too (dash does not): that stops the commands as before, and
|
|
439
|
+
`mcmd` ends `129`. A job nobody signals runs to its end: one that was `disown`ed, started with `setsid` or `nohup`, or, in
|
|
440
|
+
bash and dash, left in the background by `exit` (zsh signals its jobs on `exit` too). Over `ssh` without a pty, stdout is a
|
|
441
|
+
pipe to sshd, and a dropped connection closes it: a reader that quit. So a run that must outlive its terminal or its
|
|
442
|
+
connection, whatever starts it, runs under `nohup` (against the hang-up's SIGHUP) with its stdout in a file (which no
|
|
443
|
+
hang-up or dropped connection can close): `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD follows the same
|
|
444
|
+
rule for the writes of multiCMD's own output (its live output, `print_progress_bar()`, the report of `AsyncExecutor.join()`),
|
|
445
|
+
and none of those writes raises an `OSError` in the thread that wrote (a `sys.stdout` the program closed itself still gives
|
|
446
|
+
`ValueError`, as in 1.62: deferred to 1.64, docs/limitations.md). A reader that quit (`BrokenPipeError`, `ConnectionResetError`, or on
|
|
447
|
+
Windows `OSError` EINVAL from a pipe) stops the calls that are showing their commands (not quiet): their commands are
|
|
448
|
+
stopped as a Ctrl-C stops them, the queued ones are skipped (return code `None`), and a call that waits raises
|
|
449
|
+
`BrokenPipeError` once its commands are dead, whichever of those forms the platform gave the write (`except OSError` catches
|
|
450
|
+
it too). A pool stops all its commands, and a call on a thread of the program's own raises in that thread. Shown commands
|
|
451
|
+
nobody waits for (an `AsyncExecutor` made with `quiet=False`, `run_commands(wait_for_return=False)`; an `AsyncExecutor` is
|
|
452
|
+
quiet by default, and a quiet one is never stopped) are stopped without an error: `wait()`, `join()` and `join_threads()`
|
|
453
|
+
return, and the tasks tell (a stopped one has the kill's return code, a queued one `None`). Every call made after multiCMD
|
|
454
|
+
has found the reader gone, for the rest of the process, runs its commands unseen, and multiCMD's own stderr lines for it
|
|
455
|
+
(`Command path not found`, `Error running command`) are not printed either. So a cleanup in a `finally` (an unmount) runs
|
|
456
|
+
once an earlier shown call has raised. A call whose own first lines meet the reader quitting, or that follows only the
|
|
457
|
+
program's own write to that closed pipe, is a shown call like any other: its commands are skipped, and a call that waits raises. A cleanup that must run
|
|
458
|
+
whatever stdout does passes `quiet=True`. A quiet call never looks at stdout. One edge of the rule for calls made after the reader quit (deferred to 1.64,
|
|
459
|
+
docs/limitations.md): a shown call that starts after multiCMD has found the reader gone runs its commands unseen to their end,
|
|
460
|
+
on any thread, so a program that fans shown calls out over its own threads (a thread pool) under `prog | head` keeps running
|
|
461
|
+
as long as a remaining call's command runs (for ever, with `tail -f`); run such a fan-out as one call with `max_threads`, which stops as one. The library learns that its reader quit only from a failed write, and does not poll the pipe as `mcmd` does, so a
|
|
462
|
+
shown command that prints nothing more (`tail -f` of a log that went idle, under `prog | head -1`) runs until its next line
|
|
463
|
+
(see docs/limitations.md). Any other failed write (EIO from a terminal that hung up, ENOSPC from a full disk) loses only the
|
|
464
|
+
output: multiCMD's output is dropped from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and
|
|
465
|
+
every command runs. The program's own writes to that stdout meet the error themselves, and so does Python's flush at exit,
|
|
466
|
+
which still finds what the failed write left in `sys.stdout`'s buffer: unless the program handles that, it ends with
|
|
467
|
+
"Exception ignored" and status 120, as after a failed print of its own (a library does not redirect its caller's stdout).
|
|
468
|
+
At interpreter exit
|
|
425
469
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
426
470
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
427
471
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -429,8 +473,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
429
473
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
430
474
|
stderr, unless quiet.
|
|
431
475
|
|
|
432
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
433
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
476
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
477
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
434
478
|
|
|
435
479
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
436
480
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -506,6 +550,83 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
506
550
|
|
|
507
551
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
508
552
|
|
|
553
|
+
## Upgrading to 1.63 from 1.62
|
|
554
|
+
|
|
555
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
556
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
557
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
558
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
559
|
+
disk, a terminal that hung up) no longer gets it: the commands run, and one line on stderr says the output is dropped (1.62
|
|
560
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
561
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
562
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
563
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
564
|
+
so none blocks), says so in one line on stderr, if stderr can still take it (not with `> log 2>&1` on that disk: the log
|
|
565
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
566
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
567
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
568
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
569
|
+
(`129`), as before.
|
|
570
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
571
|
+
are dropped. 1.62 ended 120, from Python's flush at exit (`mcmd no-such-command 2>/dev/full` gave 120, not 127). On Python
|
|
572
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
573
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
574
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
575
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
576
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
577
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
578
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
579
|
+
running command" and did not run it (return code -1).
|
|
580
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
581
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
582
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
583
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
584
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
585
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
586
|
+
write errors too).
|
|
587
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
588
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
589
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
590
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
591
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
592
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
593
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
594
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
595
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
596
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
597
|
+
thread, so a fan-out over the program's own threads (a thread pool) under `prog | head` can keep running as long as a remaining
|
|
598
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
599
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
600
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
601
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
602
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
603
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
604
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
605
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
606
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
607
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
608
|
+
|
|
609
|
+
## Upgrading to 1.62 from 1.61
|
|
610
|
+
|
|
611
|
+
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
612
|
+
`ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
|
|
613
|
+
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`:
|
|
614
|
+
`nohup mcmd -q "job" > log 2>&1 &`.
|
|
615
|
+
- Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
|
|
616
|
+
waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
|
|
617
|
+
a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
|
|
618
|
+
commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
|
|
619
|
+
and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
|
|
620
|
+
- Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
|
|
621
|
+
Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
|
|
622
|
+
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;
|
|
623
|
+
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
|
|
624
|
+
that quit. The library's functions treat that `OSError` as 1.61 did.
|
|
625
|
+
- Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
|
|
626
|
+
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
|
|
627
|
+
UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
|
|
628
|
+
same in 1.59 to 1.61.
|
|
629
|
+
|
|
509
630
|
## Upgrading to 1.61 from 1.60
|
|
510
631
|
|
|
511
632
|
- Nothing needs doing to upgrade.
|
|
@@ -514,8 +635,8 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
514
635
|
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
636
|
Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
|
|
516
637
|
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
|
|
518
|
-
`BrokenPipeError`
|
|
638
|
+
covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions treat a
|
|
639
|
+
`BrokenPipeError` from `sys.stdout` as 1.60 did. A thread that finds stdout closed only says so, and the main thread's
|
|
519
640
|
waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
|
|
520
641
|
`mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
|
|
521
642
|
drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.63
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -119,7 +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
|
+
141 stdout closed ( `mcmd ... | head` ): commands stopped, ended by SIGPIPE ( 1 on Windows )
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
### Examples
|
|
@@ -193,7 +193,8 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
193
193
|
| Several commands | the number that failed, capped at `101` |
|
|
194
194
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
195
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
|
|
196
|
+
| stdout has no reader (`mcmd ... \| head`) | ended by SIGPIPE, which a shell reports as `141`; `1` on Windows |
|
|
197
|
+
| stdout fails otherwise (a full disk; a terminal that hung up, on a job its hang-up does not signal) | the commands' own status, as if it had not: every command runs, and one line on stderr says the output was lost (unless stderr is the same dead target, as with `> log 2>&1` on a full disk: then the log just stops) |
|
|
197
198
|
|
|
198
199
|
### Input files and templates
|
|
199
200
|
|
|
@@ -444,10 +445,53 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
444
445
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
445
446
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
446
447
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
447
|
-
has no reader (`mcmd ... | head
|
|
448
|
-
nothing on stderr.
|
|
449
|
-
more
|
|
450
|
-
|
|
448
|
+
has no reader (`mcmd ... | head`, or a socket its peer closed or reset): it stops them as a Ctrl-C does, and ends by
|
|
449
|
+
SIGPIPE, as `yes | head` does, with 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
|
|
450
|
+
nothing more is stopped as well (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout, and on Windows, it
|
|
451
|
+
learns it only when a write fails, and a command that prints nothing more runs to its end first (on Windows that is a known
|
|
452
|
+
limitation, docs/limitations.md). ksh93 on Linux builds its
|
|
453
|
+
pipelines from sockets, so under it `mcmd ... | head` is the same: a write finds the reader gone, as in 1.61 (bash, dash, zsh,
|
|
454
|
+
mksh, busybox and macOS's ksh give a pipe). A write to stdout that fails for any other reason (EIO from a terminal that
|
|
455
|
+
hung up, ENOSPC from a full disk; on Windows, EINVAL from anything but a pipe) loses only the output: `mcmd` drops it from
|
|
456
|
+
then on, runs every command, running and queued, says so in one line on stderr (`mcmd: cannot write to stdout ([Errno 5]
|
|
457
|
+
Input/output error): its output is dropped from here on`), if stderr can still take it, and exits with the commands' own
|
|
458
|
+
status, also with stdout and stderr on the same file. If stderr is that same dead target (`> log 2>&1` on a full disk), the
|
|
459
|
+
line is lost with the rest and the log just stops (it is written at exit if the target can take it by then). A stdout that
|
|
460
|
+
another program left non-blocking (`O_NONBLOCK`) fails with EAGAIN whenever its pipe or terminal is momentarily full, and
|
|
461
|
+
that counts as a failed write too: the output is dropped from then on. A program that imports multiCMD then never learns that
|
|
462
|
+
its reader quit: a shown `tail -f` runs on after `prog | head` has quit (`mcmd` asks the pipe, as above, and stops; see
|
|
463
|
+
docs/limitations.md). A terminal that hangs up also sends SIGHUP to the job in its foreground (a closed terminal window, or `ssh -t` whose connection drops), and bash and
|
|
464
|
+
zsh pass it on to every job they started, in the background too (dash does not): that stops the commands as before, and
|
|
465
|
+
`mcmd` ends `129`. A job nobody signals runs to its end: one that was `disown`ed, started with `setsid` or `nohup`, or, in
|
|
466
|
+
bash and dash, left in the background by `exit` (zsh signals its jobs on `exit` too). Over `ssh` without a pty, stdout is a
|
|
467
|
+
pipe to sshd, and a dropped connection closes it: a reader that quit. So a run that must outlive its terminal or its
|
|
468
|
+
connection, whatever starts it, runs under `nohup` (against the hang-up's SIGHUP) with its stdout in a file (which no
|
|
469
|
+
hang-up or dropped connection can close): `nohup mcmd -q ... > log 2>&1 &`. A program that imports multiCMD follows the same
|
|
470
|
+
rule for the writes of multiCMD's own output (its live output, `print_progress_bar()`, the report of `AsyncExecutor.join()`),
|
|
471
|
+
and none of those writes raises an `OSError` in the thread that wrote (a `sys.stdout` the program closed itself still gives
|
|
472
|
+
`ValueError`, as in 1.62: deferred to 1.64, docs/limitations.md). A reader that quit (`BrokenPipeError`, `ConnectionResetError`, or on
|
|
473
|
+
Windows `OSError` EINVAL from a pipe) stops the calls that are showing their commands (not quiet): their commands are
|
|
474
|
+
stopped as a Ctrl-C stops them, the queued ones are skipped (return code `None`), and a call that waits raises
|
|
475
|
+
`BrokenPipeError` once its commands are dead, whichever of those forms the platform gave the write (`except OSError` catches
|
|
476
|
+
it too). A pool stops all its commands, and a call on a thread of the program's own raises in that thread. Shown commands
|
|
477
|
+
nobody waits for (an `AsyncExecutor` made with `quiet=False`, `run_commands(wait_for_return=False)`; an `AsyncExecutor` is
|
|
478
|
+
quiet by default, and a quiet one is never stopped) are stopped without an error: `wait()`, `join()` and `join_threads()`
|
|
479
|
+
return, and the tasks tell (a stopped one has the kill's return code, a queued one `None`). Every call made after multiCMD
|
|
480
|
+
has found the reader gone, for the rest of the process, runs its commands unseen, and multiCMD's own stderr lines for it
|
|
481
|
+
(`Command path not found`, `Error running command`) are not printed either. So a cleanup in a `finally` (an unmount) runs
|
|
482
|
+
once an earlier shown call has raised. A call whose own first lines meet the reader quitting, or that follows only the
|
|
483
|
+
program's own write to that closed pipe, is a shown call like any other: its commands are skipped, and a call that waits raises. A cleanup that must run
|
|
484
|
+
whatever stdout does passes `quiet=True`. A quiet call never looks at stdout. One edge of the rule for calls made after the reader quit (deferred to 1.64,
|
|
485
|
+
docs/limitations.md): a shown call that starts after multiCMD has found the reader gone runs its commands unseen to their end,
|
|
486
|
+
on any thread, so a program that fans shown calls out over its own threads (a thread pool) under `prog | head` keeps running
|
|
487
|
+
as long as a remaining call's command runs (for ever, with `tail -f`); run such a fan-out as one call with `max_threads`, which stops as one. The library learns that its reader quit only from a failed write, and does not poll the pipe as `mcmd` does, so a
|
|
488
|
+
shown command that prints nothing more (`tail -f` of a log that went idle, under `prog | head -1`) runs until its next line
|
|
489
|
+
(see docs/limitations.md). Any other failed write (EIO from a terminal that hung up, ENOSPC from a full disk) loses only the
|
|
490
|
+
output: multiCMD's output is dropped from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and
|
|
491
|
+
every command runs. The program's own writes to that stdout meet the error themselves, and so does Python's flush at exit,
|
|
492
|
+
which still finds what the failed write left in `sys.stdout`'s buffer: unless the program handles that, it ends with
|
|
493
|
+
"Exception ignored" and status 120, as after a failed print of its own (a library does not redirect its caller's stdout).
|
|
494
|
+
At interpreter exit
|
|
451
495
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
452
496
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
453
497
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -455,8 +499,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
455
499
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
456
500
|
stderr, unless quiet.
|
|
457
501
|
|
|
458
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
459
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
502
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
503
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
460
504
|
|
|
461
505
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
462
506
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -532,6 +576,83 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
532
576
|
|
|
533
577
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
534
578
|
|
|
579
|
+
## Upgrading to 1.63 from 1.62
|
|
580
|
+
|
|
581
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
582
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
583
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
584
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
585
|
+
disk, a terminal that hung up) no longer gets it: the commands run, and one line on stderr says the output is dropped (1.62
|
|
586
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
587
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
588
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
589
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
590
|
+
so none blocks), says so in one line on stderr, if stderr can still take it (not with `> log 2>&1` on that disk: the log
|
|
591
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
592
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
593
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
594
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
595
|
+
(`129`), as before.
|
|
596
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
597
|
+
are dropped. 1.62 ended 120, from Python's flush at exit (`mcmd no-such-command 2>/dev/full` gave 120, not 127). On Python
|
|
598
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
599
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
600
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
601
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
602
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
603
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
604
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
605
|
+
running command" and did not run it (return code -1).
|
|
606
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
607
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
608
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
609
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
610
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
611
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
612
|
+
write errors too).
|
|
613
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
614
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
615
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
616
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
617
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
618
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
619
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
620
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
621
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
622
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
623
|
+
thread, so a fan-out over the program's own threads (a thread pool) under `prog | head` can keep running as long as a remaining
|
|
624
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
625
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
626
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
627
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
628
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
629
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
630
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
631
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
632
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
633
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
634
|
+
|
|
635
|
+
## Upgrading to 1.62 from 1.61
|
|
636
|
+
|
|
637
|
+
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
638
|
+
`ssh host 'nohup mcmd -q "job" &'` (`nohup` redirects only a stdout that is a terminal, so the pipe to sshd stays): it
|
|
639
|
+
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`:
|
|
640
|
+
`nohup mcmd -q "job" > log 2>&1 &`.
|
|
641
|
+
- Fix: `mcmd` notices a reader that quit while its commands print nothing. When stdout is a pipe on Linux and macOS, the
|
|
642
|
+
waits for the commands ask it each step (`poll()`: POLLERR on Linux, POLLHUP on macOS), so `mcmd 'sleep 4' | head -2`, and
|
|
643
|
+
a `-q` run or one under `-t` whose reader quits, stop their commands at once and end 141, where 1.61 waited for the
|
|
644
|
+
commands to end. Only a pipe is asked. With any other stdout (a file, `/dev/null`, a terminal, a socket) 1.62 asks nothing
|
|
645
|
+
and, on Linux and macOS, does what 1.61 did. Windows has no such poll: it acts on a failed write there too.
|
|
646
|
+
- Fix, Windows: a closed stdout (`mcmd ... | head`) ends `mcmd` with exit status 1 and an empty stderr, as planned in 1.61.
|
|
647
|
+
Windows reports a write to a pipe whose reader quit as `OSError` EINVAL, not `BrokenPipeError`, so 1.61 printed a traceback
|
|
648
|
+
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;
|
|
649
|
+
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
|
|
650
|
+
that quit. The library's functions treat that `OSError` as 1.61 did.
|
|
651
|
+
- Fix: `print_progress_bar` no longer raises `UnicodeEncodeError` on a stdout that cannot write its bar (Python 3.6 in a
|
|
652
|
+
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
|
|
653
|
+
UTF-8 stdout). The bar's blocks are then drawn in ASCII (`.:-=+*%#`) and what else cannot be written becomes `?`. The
|
|
654
|
+
same in 1.59 to 1.61.
|
|
655
|
+
|
|
535
656
|
## Upgrading to 1.61 from 1.60
|
|
536
657
|
|
|
537
658
|
- Nothing needs doing to upgrade.
|
|
@@ -540,8 +661,8 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
540
661
|
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
662
|
Ctrl-C does, and ends by SIGPIPE, as `yes | head` does: a shell reports 141, and stderr stays empty (exit status 1 on
|
|
542
663
|
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
|
|
544
|
-
`BrokenPipeError`
|
|
664
|
+
covers the commands' output, the summary, `--dry-run`, `-h` and `-V`. The library's functions treat a
|
|
665
|
+
`BrokenPipeError` from `sys.stdout` as 1.60 did. A thread that finds stdout closed only says so, and the main thread's
|
|
545
666
|
waits stop the commands at their next step (at most 0.1 s later), while a command not started yet is skipped;
|
|
546
667
|
`mcmd` leaves SIGPIPE ignored, as Python does, so no signal handler's raise can land inside `Popen` or where Python
|
|
547
668
|
drops it. `mcmd` learns that stdout has no reader only when a write to it fails: a command that prints nothing after
|
|
@@ -12,6 +12,7 @@ tests/test_api.py
|
|
|
12
12
|
tests/test_async_executor.py
|
|
13
13
|
tests/test_cli.py
|
|
14
14
|
tests/test_cli_closed_stdout.py
|
|
15
|
+
tests/test_cli_failed_stdout.py
|
|
15
16
|
tests/test_cli_input.py
|
|
16
17
|
tests/test_cli_summary.py
|
|
17
18
|
tests/test_display.py
|
|
@@ -29,6 +30,7 @@ tests/test_pool.py
|
|
|
29
30
|
tests/test_process_groups.py
|
|
30
31
|
tests/test_pty.py
|
|
31
32
|
tests/test_reader.py
|
|
33
|
+
tests/test_reader_quit.py
|
|
32
34
|
tests/test_regressions.py
|
|
33
35
|
tests/test_run_command.py
|
|
34
36
|
tests/test_run_commands.py
|