multiCMD 1.62__tar.gz → 1.64__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.62 → multicmd-1.64}/PKG-INFO +114 -14
- {multicmd-1.62 → multicmd-1.64}/README.md +113 -13
- {multicmd-1.62 → multicmd-1.64}/multiCMD.egg-info/PKG-INFO +114 -14
- {multicmd-1.62 → multicmd-1.64}/multiCMD.egg-info/SOURCES.txt +2 -0
- {multicmd-1.62 → multicmd-1.64}/multiCMD.py +235 -131
- {multicmd-1.62 → multicmd-1.64}/tests/test_cli_closed_stdout.py +122 -38
- multicmd-1.64/tests/test_cli_failed_stdout.py +638 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_display.py +75 -29
- {multicmd-1.62 → multicmd-1.64}/tests/test_interrupts.py +4 -1
- multicmd-1.64/tests/test_reader_quit.py +614 -0
- {multicmd-1.62 → multicmd-1.64}/LICENSE +0 -0
- {multicmd-1.62 → multicmd-1.64}/multiCMD.egg-info/dependency_links.txt +0 -0
- {multicmd-1.62 → multicmd-1.64}/multiCMD.egg-info/entry_points.txt +0 -0
- {multicmd-1.62 → multicmd-1.64}/multiCMD.egg-info/top_level.txt +0 -0
- {multicmd-1.62 → multicmd-1.64}/scripts/multiCMD +0 -0
- {multicmd-1.62 → multicmd-1.64}/setup.cfg +0 -0
- {multicmd-1.62 → multicmd-1.64}/setup.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_api.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_async_executor.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_cli.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_cli_input.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_cli_summary.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_embed.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_env.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_expand_ranges.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_handover.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_helpers.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_packaging.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_parsing.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_pass_fds.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_ping.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_pool.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_process_groups.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_pty.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_reader.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_regressions.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_run_command.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_run_commands.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_sudo.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_supervision.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/tests/test_task.py +0 -0
- {multicmd-1.62 → multicmd-1.64}/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.64
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -194,6 +194,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
194
194
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
195
195
|
| Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
|
|
196
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,15 +445,7 @@ 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 (
|
|
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
|
|
448
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
456
449
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
457
450
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
458
451
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -460,8 +453,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
460
453
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
461
454
|
stderr, unless quiet.
|
|
462
455
|
|
|
463
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
464
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
456
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
457
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
465
458
|
|
|
466
459
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
467
460
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -488,6 +481,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
488
481
|
answers.
|
|
489
482
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
490
483
|
|
|
484
|
+
## When stdout fails
|
|
485
|
+
|
|
486
|
+
<!-- Each cell's tests ( tests/ ): mcmd, reader quit: test_cli_closed_stdout.py ( test_a_reader_that_quits_ends_the_cli_by_sigpipe_and_stops_its_commands,
|
|
487
|
+
test_a_reader_that_quits_while_the_commands_print_nothing_ends_the_cli_at_once ), test_cli_failed_stdout.py ( test_a_socket_its_peer_reset_ends_the_cli_by_sigpipe_and_stops_its_commands ).
|
|
488
|
+
Library, reader quit: test_reader_quit.py ( test_a_program_whose_reader_quit_stops_its_command_and_gets_broken_pipe_error, test_shown_calls_fanned_out_over_the_programs_threads_all_end,
|
|
489
|
+
test_a_shown_command_that_prints_nothing_runs_whoever_met_the_reader_quitting_first, test_the_last_words_of_a_command_that_then_ends_are_only_lost,
|
|
490
|
+
test_a_second_piece_of_output_at_half_the_window_is_still_last_words, test_a_second_piece_of_output_at_one_and_a_half_times_the_window_stops_the_call,
|
|
491
|
+
test_last_words_that_arrive_at_once_are_only_lost, test_a_call_of_commands_that_each_print_once_runs_them_all_and_returns,
|
|
492
|
+
test_output_without_line_ends_that_keeps_coming_stops_its_call, test_a_command_that_exits_and_leaves_a_follower_holding_its_output_stops_its_call,
|
|
493
|
+
test_a_shown_dry_run_whose_reader_quit_raises,
|
|
494
|
+
test_a_shown_dry_run_made_after_the_reader_quit_raises, test_output_shown_before_the_quit_does_not_count_against_the_last_words,
|
|
495
|
+
test_commands_nobody_waits_for_are_stopped_and_their_tasks_say_so, test_a_quiet_call_never_looks_at_stdout ).
|
|
496
|
+
mcmd, other failed write: test_cli_failed_stdout.py ( test_a_terminal_that_hung_up_loses_the_output_and_every_command_runs, test_a_full_disk_under_stdout_loses_the_output_and_every_command_runs ).
|
|
497
|
+
Library, other failed write: test_reader_quit.py ( test_any_other_failed_write_still_loses_only_the_output ), test_cli_failed_stdout.py ( test_the_library_runs_every_command_when_stdout_fails,
|
|
498
|
+
test_a_program_that_imports_multicmd_still_meets_the_failed_write_at_exit, test_a_sys_stdout_the_program_closed_loses_the_output_and_every_command_runs ).
|
|
499
|
+
Closed at start: test_cli_failed_stdout.py ( test_a_stdout_closed_at_start_drops_the_output_and_every_command_runs, test_the_library_runs_every_command_with_stdout_closed_at_start ). -->
|
|
500
|
+
|
|
501
|
+
| What happened to stdout | `mcmd` | A program that imports multiCMD |
|
|
502
|
+
|---|---|---|
|
|
503
|
+
| Its reader quit (`... \| head`, a socket its peer closed or reset) | Stops every command as a Ctrl-C does and ends by SIGPIPE (141; 1 on Windows), with nothing on stderr | A shown command whose output keeps coming after the quit is stopped, and so is the rest of its call: its queued commands are skipped and, if it waits, the call raises `BrokenPipeError`. A call whose commands print nothing more, or only their last words (all within 1 s), runs them all to their end, queued commands included. A quiet call never looks at stdout |
|
|
504
|
+
| Any other failed write (a terminal that hung up, a full disk; in a program, a `sys.stdout` it closed) | The output is dropped from then on, one line on stderr says so if stderr can still take it, every command runs, and the exit status is the commands' own | The same, and nothing is raised; the program's own writes still meet the error (a library does not redirect its caller's stdout) |
|
|
505
|
+
| Closed at start (`>&-`) | The output is dropped silently; every command runs | The same (`sys.stdout` is `None`) |
|
|
506
|
+
|
|
507
|
+
On Linux and macOS, with stdout on a pipe, `mcmd` asks the pipe as it waits, so a command that prints nothing more is
|
|
508
|
+
stopped too (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout (a socket, as ksh93 on Linux builds its
|
|
509
|
+
pipelines), and on Windows, it learns that its reader quit from its next failed write. A run that must outlive its terminal
|
|
510
|
+
or its connection: `nohup mcmd -q ... > log 2>&1 &`. In a program, a cleanup that must run whatever stdout does passes
|
|
511
|
+
`quiet=True`. The exceptions, with their evidence, are in [docs/limitations.md](docs/limitations.md).
|
|
512
|
+
|
|
491
513
|
## Key functions and objects
|
|
492
514
|
|
|
493
515
|
```python
|
|
@@ -516,8 +538,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
516
538
|
|
|
517
539
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
518
540
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
519
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
520
|
-
`slugify`.
|
|
541
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
542
|
+
stderr), and `slugify`.
|
|
521
543
|
|
|
522
544
|
## Platform support
|
|
523
545
|
|
|
@@ -537,6 +559,84 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
537
559
|
|
|
538
560
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
539
561
|
|
|
562
|
+
## Upgrading to 1.64 from 1.63
|
|
563
|
+
|
|
564
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
565
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
566
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
567
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
568
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
569
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
570
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
571
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
572
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
573
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
574
|
+
(1.63: a dry run made after the reader quit returned).
|
|
575
|
+
- hpcp 9.89 and 9.90 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
576
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
577
|
+
detached, where 1.63 ran it unseen; a later hpcp runs its cleanup quiet.
|
|
578
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
579
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
580
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
581
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
582
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
583
|
+
|
|
584
|
+
## Upgrading to 1.63 from 1.62
|
|
585
|
+
|
|
586
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
587
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
588
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
589
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
590
|
+
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
|
|
591
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
592
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
593
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
594
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
595
|
+
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
|
|
596
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
597
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
598
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
599
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
600
|
+
(`129`), as before.
|
|
601
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
602
|
+
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
|
|
603
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
604
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
605
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
606
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
607
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
608
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
609
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
610
|
+
running command" and did not run it (return code -1).
|
|
611
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
612
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
613
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
614
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
615
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
616
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
617
|
+
write errors too).
|
|
618
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
619
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
620
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
621
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
622
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
623
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
624
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
625
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
626
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
627
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
628
|
+
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
|
|
629
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
630
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
631
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
632
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
633
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
634
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
635
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
636
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
637
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
638
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
639
|
+
|
|
540
640
|
## Upgrading to 1.62 from 1.61
|
|
541
641
|
|
|
542
642
|
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
@@ -168,6 +168,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
168
168
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
169
169
|
| Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
|
|
170
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,15 +419,7 @@ 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 (
|
|
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
|
|
422
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
430
423
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
431
424
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
432
425
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -434,8 +427,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
434
427
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
435
428
|
stderr, unless quiet.
|
|
436
429
|
|
|
437
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
438
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
430
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
431
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
439
432
|
|
|
440
433
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
441
434
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -462,6 +455,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
462
455
|
answers.
|
|
463
456
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
464
457
|
|
|
458
|
+
## When stdout fails
|
|
459
|
+
|
|
460
|
+
<!-- Each cell's tests ( tests/ ): mcmd, reader quit: test_cli_closed_stdout.py ( test_a_reader_that_quits_ends_the_cli_by_sigpipe_and_stops_its_commands,
|
|
461
|
+
test_a_reader_that_quits_while_the_commands_print_nothing_ends_the_cli_at_once ), test_cli_failed_stdout.py ( test_a_socket_its_peer_reset_ends_the_cli_by_sigpipe_and_stops_its_commands ).
|
|
462
|
+
Library, reader quit: test_reader_quit.py ( test_a_program_whose_reader_quit_stops_its_command_and_gets_broken_pipe_error, test_shown_calls_fanned_out_over_the_programs_threads_all_end,
|
|
463
|
+
test_a_shown_command_that_prints_nothing_runs_whoever_met_the_reader_quitting_first, test_the_last_words_of_a_command_that_then_ends_are_only_lost,
|
|
464
|
+
test_a_second_piece_of_output_at_half_the_window_is_still_last_words, test_a_second_piece_of_output_at_one_and_a_half_times_the_window_stops_the_call,
|
|
465
|
+
test_last_words_that_arrive_at_once_are_only_lost, test_a_call_of_commands_that_each_print_once_runs_them_all_and_returns,
|
|
466
|
+
test_output_without_line_ends_that_keeps_coming_stops_its_call, test_a_command_that_exits_and_leaves_a_follower_holding_its_output_stops_its_call,
|
|
467
|
+
test_a_shown_dry_run_whose_reader_quit_raises,
|
|
468
|
+
test_a_shown_dry_run_made_after_the_reader_quit_raises, test_output_shown_before_the_quit_does_not_count_against_the_last_words,
|
|
469
|
+
test_commands_nobody_waits_for_are_stopped_and_their_tasks_say_so, test_a_quiet_call_never_looks_at_stdout ).
|
|
470
|
+
mcmd, other failed write: test_cli_failed_stdout.py ( test_a_terminal_that_hung_up_loses_the_output_and_every_command_runs, test_a_full_disk_under_stdout_loses_the_output_and_every_command_runs ).
|
|
471
|
+
Library, other failed write: test_reader_quit.py ( test_any_other_failed_write_still_loses_only_the_output ), test_cli_failed_stdout.py ( test_the_library_runs_every_command_when_stdout_fails,
|
|
472
|
+
test_a_program_that_imports_multicmd_still_meets_the_failed_write_at_exit, test_a_sys_stdout_the_program_closed_loses_the_output_and_every_command_runs ).
|
|
473
|
+
Closed at start: test_cli_failed_stdout.py ( test_a_stdout_closed_at_start_drops_the_output_and_every_command_runs, test_the_library_runs_every_command_with_stdout_closed_at_start ). -->
|
|
474
|
+
|
|
475
|
+
| What happened to stdout | `mcmd` | A program that imports multiCMD |
|
|
476
|
+
|---|---|---|
|
|
477
|
+
| Its reader quit (`... \| head`, a socket its peer closed or reset) | Stops every command as a Ctrl-C does and ends by SIGPIPE (141; 1 on Windows), with nothing on stderr | A shown command whose output keeps coming after the quit is stopped, and so is the rest of its call: its queued commands are skipped and, if it waits, the call raises `BrokenPipeError`. A call whose commands print nothing more, or only their last words (all within 1 s), runs them all to their end, queued commands included. A quiet call never looks at stdout |
|
|
478
|
+
| Any other failed write (a terminal that hung up, a full disk; in a program, a `sys.stdout` it closed) | The output is dropped from then on, one line on stderr says so if stderr can still take it, every command runs, and the exit status is the commands' own | The same, and nothing is raised; the program's own writes still meet the error (a library does not redirect its caller's stdout) |
|
|
479
|
+
| Closed at start (`>&-`) | The output is dropped silently; every command runs | The same (`sys.stdout` is `None`) |
|
|
480
|
+
|
|
481
|
+
On Linux and macOS, with stdout on a pipe, `mcmd` asks the pipe as it waits, so a command that prints nothing more is
|
|
482
|
+
stopped too (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout (a socket, as ksh93 on Linux builds its
|
|
483
|
+
pipelines), and on Windows, it learns that its reader quit from its next failed write. A run that must outlive its terminal
|
|
484
|
+
or its connection: `nohup mcmd -q ... > log 2>&1 &`. In a program, a cleanup that must run whatever stdout does passes
|
|
485
|
+
`quiet=True`. The exceptions, with their evidence, are in [docs/limitations.md](docs/limitations.md).
|
|
486
|
+
|
|
465
487
|
## Key functions and objects
|
|
466
488
|
|
|
467
489
|
```python
|
|
@@ -490,8 +512,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
490
512
|
|
|
491
513
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
492
514
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
493
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
494
|
-
`slugify`.
|
|
515
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
516
|
+
stderr), and `slugify`.
|
|
495
517
|
|
|
496
518
|
## Platform support
|
|
497
519
|
|
|
@@ -511,6 +533,84 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
511
533
|
|
|
512
534
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
513
535
|
|
|
536
|
+
## Upgrading to 1.64 from 1.63
|
|
537
|
+
|
|
538
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
539
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
540
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
541
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
542
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
543
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
544
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
545
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
546
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
547
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
548
|
+
(1.63: a dry run made after the reader quit returned).
|
|
549
|
+
- hpcp 9.89 and 9.90 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
550
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
551
|
+
detached, where 1.63 ran it unseen; a later hpcp runs its cleanup quiet.
|
|
552
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
553
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
554
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
555
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
556
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
557
|
+
|
|
558
|
+
## Upgrading to 1.63 from 1.62
|
|
559
|
+
|
|
560
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
561
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
562
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
563
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
564
|
+
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
|
|
565
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
566
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
567
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
568
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
569
|
+
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
|
|
570
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
571
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
572
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
573
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
574
|
+
(`129`), as before.
|
|
575
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
576
|
+
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
|
|
577
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
578
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
579
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
580
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
581
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
582
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
583
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
584
|
+
running command" and did not run it (return code -1).
|
|
585
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
586
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
587
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
588
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
589
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
590
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
591
|
+
write errors too).
|
|
592
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
593
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
594
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
595
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
596
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
597
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
598
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
599
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
600
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
601
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
602
|
+
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
|
|
603
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
604
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
605
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
606
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
607
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
608
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
609
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
610
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
611
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
612
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
613
|
+
|
|
514
614
|
## Upgrading to 1.62 from 1.61
|
|
515
615
|
|
|
516
616
|
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.64
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -194,6 +194,7 @@ mcmd --shell -m 4 "dmesg | tail -n 5" "journalctl -n 5 > /tmp/j.log"
|
|
|
194
194
|
| Usage error (bad option, unbalanced quote, no commands) | `2` |
|
|
195
195
|
| Ctrl-C | `130` (`128+N` after SIGTERM / SIGHUP) |
|
|
196
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,15 +445,7 @@ 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 (
|
|
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
|
|
448
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
456
449
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
457
450
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
458
451
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -460,8 +453,8 @@ multiCMD from its own threads (where Ctrl-C never arrives), can call `multiCMD.k
|
|
|
460
453
|
handler. A command not seen to exit a second after SIGKILL is no longer tracked; its pid is named on
|
|
461
454
|
stderr, unless quiet.
|
|
462
455
|
|
|
463
|
-
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers,
|
|
464
|
-
else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
456
|
+
multiCMD never touches SIGINT's handler (`mcmd` sets its own SIGTERM / SIGHUP handlers and ignores SIGTTIN / SIGTTOU,
|
|
457
|
+
nothing else). What your handler raises while a call waits for its commands is handled as a Ctrl-C.
|
|
465
458
|
|
|
466
459
|
A command is registered from the moment `Popen` returns it. Before Python 3.11 the exec wrapper runs
|
|
467
460
|
the command only once it is registered, so a Ctrl-C that Python raises inside `Popen` as a serial run
|
|
@@ -488,6 +481,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
488
481
|
answers.
|
|
489
482
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
490
483
|
|
|
484
|
+
## When stdout fails
|
|
485
|
+
|
|
486
|
+
<!-- Each cell's tests ( tests/ ): mcmd, reader quit: test_cli_closed_stdout.py ( test_a_reader_that_quits_ends_the_cli_by_sigpipe_and_stops_its_commands,
|
|
487
|
+
test_a_reader_that_quits_while_the_commands_print_nothing_ends_the_cli_at_once ), test_cli_failed_stdout.py ( test_a_socket_its_peer_reset_ends_the_cli_by_sigpipe_and_stops_its_commands ).
|
|
488
|
+
Library, reader quit: test_reader_quit.py ( test_a_program_whose_reader_quit_stops_its_command_and_gets_broken_pipe_error, test_shown_calls_fanned_out_over_the_programs_threads_all_end,
|
|
489
|
+
test_a_shown_command_that_prints_nothing_runs_whoever_met_the_reader_quitting_first, test_the_last_words_of_a_command_that_then_ends_are_only_lost,
|
|
490
|
+
test_a_second_piece_of_output_at_half_the_window_is_still_last_words, test_a_second_piece_of_output_at_one_and_a_half_times_the_window_stops_the_call,
|
|
491
|
+
test_last_words_that_arrive_at_once_are_only_lost, test_a_call_of_commands_that_each_print_once_runs_them_all_and_returns,
|
|
492
|
+
test_output_without_line_ends_that_keeps_coming_stops_its_call, test_a_command_that_exits_and_leaves_a_follower_holding_its_output_stops_its_call,
|
|
493
|
+
test_a_shown_dry_run_whose_reader_quit_raises,
|
|
494
|
+
test_a_shown_dry_run_made_after_the_reader_quit_raises, test_output_shown_before_the_quit_does_not_count_against_the_last_words,
|
|
495
|
+
test_commands_nobody_waits_for_are_stopped_and_their_tasks_say_so, test_a_quiet_call_never_looks_at_stdout ).
|
|
496
|
+
mcmd, other failed write: test_cli_failed_stdout.py ( test_a_terminal_that_hung_up_loses_the_output_and_every_command_runs, test_a_full_disk_under_stdout_loses_the_output_and_every_command_runs ).
|
|
497
|
+
Library, other failed write: test_reader_quit.py ( test_any_other_failed_write_still_loses_only_the_output ), test_cli_failed_stdout.py ( test_the_library_runs_every_command_when_stdout_fails,
|
|
498
|
+
test_a_program_that_imports_multicmd_still_meets_the_failed_write_at_exit, test_a_sys_stdout_the_program_closed_loses_the_output_and_every_command_runs ).
|
|
499
|
+
Closed at start: test_cli_failed_stdout.py ( test_a_stdout_closed_at_start_drops_the_output_and_every_command_runs, test_the_library_runs_every_command_with_stdout_closed_at_start ). -->
|
|
500
|
+
|
|
501
|
+
| What happened to stdout | `mcmd` | A program that imports multiCMD |
|
|
502
|
+
|---|---|---|
|
|
503
|
+
| Its reader quit (`... \| head`, a socket its peer closed or reset) | Stops every command as a Ctrl-C does and ends by SIGPIPE (141; 1 on Windows), with nothing on stderr | A shown command whose output keeps coming after the quit is stopped, and so is the rest of its call: its queued commands are skipped and, if it waits, the call raises `BrokenPipeError`. A call whose commands print nothing more, or only their last words (all within 1 s), runs them all to their end, queued commands included. A quiet call never looks at stdout |
|
|
504
|
+
| Any other failed write (a terminal that hung up, a full disk; in a program, a `sys.stdout` it closed) | The output is dropped from then on, one line on stderr says so if stderr can still take it, every command runs, and the exit status is the commands' own | The same, and nothing is raised; the program's own writes still meet the error (a library does not redirect its caller's stdout) |
|
|
505
|
+
| Closed at start (`>&-`) | The output is dropped silently; every command runs | The same (`sys.stdout` is `None`) |
|
|
506
|
+
|
|
507
|
+
On Linux and macOS, with stdout on a pipe, `mcmd` asks the pipe as it waits, so a command that prints nothing more is
|
|
508
|
+
stopped too (`mcmd 'sleep 4' | head -2` ends at once); with any other stdout (a socket, as ksh93 on Linux builds its
|
|
509
|
+
pipelines), and on Windows, it learns that its reader quit from its next failed write. A run that must outlive its terminal
|
|
510
|
+
or its connection: `nohup mcmd -q ... > log 2>&1 &`. In a program, a cleanup that must run whatever stdout does passes
|
|
511
|
+
`quiet=True`. The exceptions, with their evidence, are in [docs/limitations.md](docs/limitations.md).
|
|
512
|
+
|
|
491
513
|
## Key functions and objects
|
|
492
514
|
|
|
493
515
|
```python
|
|
@@ -516,8 +538,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
516
538
|
|
|
517
539
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
518
540
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
519
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
520
|
-
`slugify`.
|
|
541
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
542
|
+
stderr), and `slugify`.
|
|
521
543
|
|
|
522
544
|
## Platform support
|
|
523
545
|
|
|
@@ -537,6 +559,84 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
537
559
|
|
|
538
560
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
539
561
|
|
|
562
|
+
## Upgrading to 1.64 from 1.63
|
|
563
|
+
|
|
564
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
565
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
566
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
567
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
568
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
569
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
570
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
571
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
572
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
573
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
574
|
+
(1.63: a dry run made after the reader quit returned).
|
|
575
|
+
- hpcp 9.89 and 9.90 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
576
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
577
|
+
detached, where 1.63 ran it unseen; a later hpcp runs its cleanup quiet.
|
|
578
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
579
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
580
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
581
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
582
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
583
|
+
|
|
584
|
+
## Upgrading to 1.63 from 1.62
|
|
585
|
+
|
|
586
|
+
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
587
|
+
shown call now gets `BrokenPipeError` for a reset socket (catch `OSError` or `BrokenPipeError`). One that relied on 1.62's
|
|
588
|
+
error from every shown call made after the reader quit (a loop that catches per item, a thread pool) now has those calls
|
|
589
|
+
run unseen: see the library bullet below. One that caught `OSError` from a shown call to learn that stdout failed (a full
|
|
590
|
+
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
|
|
591
|
+
raised the error from a serial call and ran nothing, and a pool returned -1).
|
|
592
|
+
- Fix: a write to stdout that fails for another reason than a reader quitting no longer breaks the run. With a terminal that
|
|
593
|
+
hung up on a job nobody signals (EIO: `setsid mcmd ...` or a `disown`ed job) or a full disk (ENOSPC), `mcmd`
|
|
594
|
+
drops its output from then on, runs every command (running and queued, serial and with `-m`; their output is still read,
|
|
595
|
+
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
|
|
596
|
+
just stops), and exits with the commands' own status, `> log 2>&1` included. 1.62 printed
|
|
597
|
+
tracebacks, did not start the queued commands, often lost the running ones (they died at their next line), and exited 120.
|
|
598
|
+
`-h`, `-V` and `-n` to a full disk end 0 with that line, where 1.62 ended 120 with "Exception ignored". A job its
|
|
599
|
+
terminal's hang-up signals (the foreground job; any job of bash or zsh) still gets SIGHUP when it hangs up, and stops
|
|
600
|
+
(`129`), as before.
|
|
601
|
+
- Fix: a stderr that cannot be written (`mcmd ... 2>/dev/full`, or a pipe nobody reads) changes no exit status: its messages
|
|
602
|
+
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
|
|
603
|
+
3.9 and 3.10 a usage error then ends 1, not 2 (1.62: 120).
|
|
604
|
+
- Fix: `mcmd ... 2>&-` (stderr closed at start) puts none of its messages, and no usage error, into stdout. 1.62 wrote them
|
|
605
|
+
there (`Command path not found`, `mcmd: no commands to run`, argparse's usage), and a usage error ended 1 on Python 3.6 and
|
|
606
|
+
3.9. In a program that imports multiCMD, its warnings and failure messages are dropped then, not written to stdout.
|
|
607
|
+
- Fix: `mcmd ... >&-` (stdout closed at start) drops the output silently and runs every command. 1.62 printed "Error running
|
|
608
|
+
command" and a traceback, and a serial run did not start its commands. In a program that imports multiCMD, a `None`
|
|
609
|
+
`sys.stdout` does the same: the output is dropped and the command runs, where 1.62 raised `AttributeError`, printed "Error
|
|
610
|
+
running command" and did not run it (return code -1).
|
|
611
|
+
- Fix, Python 3.6 in a C locale (ASCII stdout): a command's non-ASCII output is shown with backslash escapes (`caf\xe9`).
|
|
612
|
+
1.62 killed the thread that read the command's output with a `UnicodeEncodeError`.
|
|
613
|
+
- Fix: a socket its peer reset (ECONNRESET) is a reader that quit, as a closed pipe is: `mcmd` stops its commands and ends
|
|
614
|
+
141 with nothing on stderr. 1.62 printed a traceback, or an "Error running command" line, for it.
|
|
615
|
+
- Changed, Windows: EINVAL from a write to stdout is a reader that quit only when stdout is a pipe. On any other stdout
|
|
616
|
+
it loses the output as above, where 1.62 stopped the commands and exited 1 (Windows' C runtime gives EINVAL for other
|
|
617
|
+
write errors too).
|
|
618
|
+
- Changed, library: a failed write of multiCMD's own output (not quiet) no longer raises in the thread that wrote, and
|
|
619
|
+
`BrokenPipeError` now means a reader that quit, in every form. A reader that quit (EPIPE, ECONNRESET, on Windows EINVAL
|
|
620
|
+
from a pipe) stops the calls that show their commands: they stop them, skip the queued ones, and a waiting
|
|
621
|
+
`run_commands()` (`run_command()` too) raises `BrokenPipeError` once they are dead. 1.62 documented "`BrokenPipeError`;
|
|
622
|
+
`OSError` EINVAL on Windows", and a reset socket gave `ConnectionResetError`: now it is one error, and `except OSError`
|
|
623
|
+
catches it as before. Shown commands nobody waits for (an `AsyncExecutor` made with `quiet=False`,
|
|
624
|
+
or `run_commands(..., wait_for_return=False)`; an `AsyncExecutor` is quiet by default, and is then never stopped) are stopped without an error.
|
|
625
|
+
Calls made after multiCMD has found the reader gone run their commands unseen, without multiCMD's own stderr lines, where
|
|
626
|
+
1.62 raised again and ran nothing (a cleanup still runs, unseen, once an earlier shown call has raised; one that must run
|
|
627
|
+
whatever stdout does passes `quiet=True`). A shown call that starts after that runs its commands unseen to their end on any
|
|
628
|
+
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
|
|
629
|
+
call's command runs, where 1.62 raised in every call: run it as one call with `max_threads`, which stops as one
|
|
630
|
+
(deferred to 1.64, docs/limitations.md). The library does not poll the pipe as `mcmd` does: a shown command that prints nothing more
|
|
631
|
+
runs until its next line (docs/limitations.md; 1.62's was the same). Any other failed write only loses the output: dropped
|
|
632
|
+
from then on, one line on stderr says so (`multiCMD: cannot write to stdout ...`), and every command runs. 1.62 raised the
|
|
633
|
+
error in the thread that wrote: a command whose "Running command" line could not be written counted as failed (-1) without
|
|
634
|
+
running, a reader that could not write a line died with a traceback, taking the command's output pipe with it, a pool
|
|
635
|
+
worker left a traceback, and a serial call raised the error to the caller. `print_progress_bar()` and the report of
|
|
636
|
+
`AsyncExecutor.join()` meet the same rule (1.62: `OSError` from a terminal that hung up). A program that imports
|
|
637
|
+
multiCMD meets the error in its own next write to that stdout, and in Python's flush at exit, which still finds what the
|
|
638
|
+
failed write left in `sys.stdout`'s buffer ("Exception ignored" and status 120, unless the program handles it).
|
|
639
|
+
|
|
540
640
|
## Upgrading to 1.62 from 1.61
|
|
541
641
|
|
|
542
642
|
- Nothing needs doing to upgrade, except for a run that must outlive whatever reads its stdout, such as
|
|
@@ -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
|