multiCMD 1.63__tar.gz → 1.65__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.63 → multicmd-1.65}/PKG-INFO +70 -50
- {multicmd-1.63 → multicmd-1.65}/README.md +69 -49
- {multicmd-1.63 → multicmd-1.65}/multiCMD.egg-info/PKG-INFO +70 -50
- {multicmd-1.63 → multicmd-1.65}/multiCMD.py +167 -133
- {multicmd-1.63 → multicmd-1.65}/tests/test_cli_closed_stdout.py +32 -3
- {multicmd-1.63 → multicmd-1.65}/tests/test_cli_failed_stdout.py +153 -0
- multicmd-1.65/tests/test_helpers.py +423 -0
- multicmd-1.65/tests/test_reader_quit.py +614 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_supervision.py +2 -2
- {multicmd-1.63 → multicmd-1.65}/tests/test_windows.py +18 -0
- multicmd-1.63/tests/test_helpers.py +0 -162
- multicmd-1.63/tests/test_reader_quit.py +0 -274
- {multicmd-1.63 → multicmd-1.65}/LICENSE +0 -0
- {multicmd-1.63 → multicmd-1.65}/multiCMD.egg-info/SOURCES.txt +0 -0
- {multicmd-1.63 → multicmd-1.65}/multiCMD.egg-info/dependency_links.txt +0 -0
- {multicmd-1.63 → multicmd-1.65}/multiCMD.egg-info/entry_points.txt +0 -0
- {multicmd-1.63 → multicmd-1.65}/multiCMD.egg-info/top_level.txt +0 -0
- {multicmd-1.63 → multicmd-1.65}/scripts/multiCMD +0 -0
- {multicmd-1.63 → multicmd-1.65}/setup.cfg +0 -0
- {multicmd-1.63 → multicmd-1.65}/setup.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_api.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_async_executor.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_cli.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_cli_input.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_cli_summary.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_display.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_embed.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_env.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_expand_ranges.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_handover.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_interrupts.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_packaging.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_parsing.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_pass_fds.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_ping.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_pool.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_process_groups.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_pty.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_reader.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_regressions.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_run_command.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_run_commands.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_sudo.py +0 -0
- {multicmd-1.63 → multicmd-1.65}/tests/test_task.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.65
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -445,53 +445,7 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
445
445
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
446
446
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
447
447
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
448
|
-
has no reader (
|
|
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
|
|
448
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
495
449
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
496
450
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
497
451
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -527,6 +481,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
527
481
|
answers.
|
|
528
482
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
529
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
|
+
|
|
530
513
|
## Key functions and objects
|
|
531
514
|
|
|
532
515
|
```python
|
|
@@ -555,8 +538,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
555
538
|
|
|
556
539
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
557
540
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
558
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
559
|
-
`slugify`.
|
|
541
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
542
|
+
stderr), and `slugify`.
|
|
560
543
|
|
|
561
544
|
## Platform support
|
|
562
545
|
|
|
@@ -576,6 +559,43 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
576
559
|
|
|
577
560
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
578
561
|
|
|
562
|
+
## Upgrading to 1.65 from 1.64
|
|
563
|
+
|
|
564
|
+
- Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
|
|
565
|
+
to 9.91 takes the `0` below as a size where 1.64 stopped with a `TypeError`, and 9.92 refuses a size with a unit it cannot
|
|
566
|
+
read before anything is touched.
|
|
567
|
+
- Changed, library: `format_bytes()` given a string with a unit it does not know (`'5 foo'`) returns `0` and writes the
|
|
568
|
+
"Invalid size format" line to stderr, as for a string with no number (1.64: `None`). A program that cannot tell this `0`
|
|
569
|
+
from a real one checks the string itself.
|
|
570
|
+
- Changed, library: `input_with_timeout_and_countdown()` counts an ended stdin (Ctrl-D, `/dev/null`), a closed one or none
|
|
571
|
+
as no answer: it returns `None` when the countdown ends, never sooner (1.64: an exception). It goes on asking meanwhile,
|
|
572
|
+
so Ctrl-C still aborts and a line typed before the end is taken. A program that caught `EOFError` to skip the prompt now
|
|
573
|
+
waits the countdown out.
|
|
574
|
+
- Known, planned for 1.66 ([docs/limitations.md](docs/limitations.md)): Ctrl-D after a half-typed line stops the countdown
|
|
575
|
+
until the line is ended, and `format_bytes()` ignores text after the size (`'5Gb/s'` is 5 G).
|
|
576
|
+
|
|
577
|
+
## Upgrading to 1.64 from 1.63
|
|
578
|
+
|
|
579
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
580
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
581
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
582
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
583
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
584
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
585
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
586
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
587
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
588
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
589
|
+
(1.63: a dry run made after the reader quit returned).
|
|
590
|
+
- hpcp 9.89 to 9.91 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
591
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
592
|
+
detached, where 1.63 ran it unseen; hpcp 9.92 runs its cleanup quiet.
|
|
593
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
594
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
595
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
596
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
597
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
598
|
+
|
|
579
599
|
## Upgrading to 1.63 from 1.62
|
|
580
600
|
|
|
581
601
|
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
@@ -419,53 +419,7 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
419
419
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
420
420
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
421
421
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
422
|
-
has no reader (
|
|
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
|
|
422
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
469
423
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
470
424
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
471
425
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -501,6 +455,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
501
455
|
answers.
|
|
502
456
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
503
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
|
+
|
|
504
487
|
## Key functions and objects
|
|
505
488
|
|
|
506
489
|
```python
|
|
@@ -529,8 +512,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
529
512
|
|
|
530
513
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
531
514
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
532
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
533
|
-
`slugify`.
|
|
515
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
516
|
+
stderr), and `slugify`.
|
|
534
517
|
|
|
535
518
|
## Platform support
|
|
536
519
|
|
|
@@ -550,6 +533,43 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
550
533
|
|
|
551
534
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
552
535
|
|
|
536
|
+
## Upgrading to 1.65 from 1.64
|
|
537
|
+
|
|
538
|
+
- Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
|
|
539
|
+
to 9.91 takes the `0` below as a size where 1.64 stopped with a `TypeError`, and 9.92 refuses a size with a unit it cannot
|
|
540
|
+
read before anything is touched.
|
|
541
|
+
- Changed, library: `format_bytes()` given a string with a unit it does not know (`'5 foo'`) returns `0` and writes the
|
|
542
|
+
"Invalid size format" line to stderr, as for a string with no number (1.64: `None`). A program that cannot tell this `0`
|
|
543
|
+
from a real one checks the string itself.
|
|
544
|
+
- Changed, library: `input_with_timeout_and_countdown()` counts an ended stdin (Ctrl-D, `/dev/null`), a closed one or none
|
|
545
|
+
as no answer: it returns `None` when the countdown ends, never sooner (1.64: an exception). It goes on asking meanwhile,
|
|
546
|
+
so Ctrl-C still aborts and a line typed before the end is taken. A program that caught `EOFError` to skip the prompt now
|
|
547
|
+
waits the countdown out.
|
|
548
|
+
- Known, planned for 1.66 ([docs/limitations.md](docs/limitations.md)): Ctrl-D after a half-typed line stops the countdown
|
|
549
|
+
until the line is ended, and `format_bytes()` ignores text after the size (`'5Gb/s'` is 5 G).
|
|
550
|
+
|
|
551
|
+
## Upgrading to 1.64 from 1.63
|
|
552
|
+
|
|
553
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
554
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
555
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
556
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
557
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
558
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
559
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
560
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
561
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
562
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
563
|
+
(1.63: a dry run made after the reader quit returned).
|
|
564
|
+
- hpcp 9.89 to 9.91 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
565
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
566
|
+
detached, where 1.63 ran it unseen; hpcp 9.92 runs its cleanup quiet.
|
|
567
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
568
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
569
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
570
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
571
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
572
|
+
|
|
553
573
|
## Upgrading to 1.63 from 1.62
|
|
554
574
|
|
|
555
575
|
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiCMD
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.65
|
|
4
4
|
Summary: Run commands simultaneously
|
|
5
5
|
Home-page: https://github.com/yufei-pan/multiCMD
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -445,53 +445,7 @@ Ctrl-C (or a SIGTERM handler's `sys.exit()`) in a call waiting on the main threa
|
|
|
445
445
|
and `AsyncExecutor.wait()` included, stops every command, skips the queued ones and
|
|
446
446
|
re-raises, giving them up to 5 s to exit; a second Ctrl-C ends that wait at once. `mcmd` stops its
|
|
447
447
|
commands on SIGTERM / SIGHUP (unless started with them ignored, as under `nohup`), and when its stdout
|
|
448
|
-
has no reader (
|
|
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
|
|
448
|
+
has no reader (see [When stdout fails](#when-stdout-fails)). At interpreter exit
|
|
495
449
|
the commands still running are killed, and a command queued on one of multiCMD's threads fails (-1,
|
|
496
450
|
"not started: the interpreter is exiting") instead of outliving the program; one run from an `atexit`
|
|
497
451
|
handler after that, on the main thread, runs as usual. A program that handles SIGTERM itself, or runs
|
|
@@ -527,6 +481,35 @@ exec of the Python binary itself hangs (a venv on an NFS mount that stopped answ
|
|
|
527
481
|
answers.
|
|
528
482
|
These and the other known limits are in [docs/limitations.md](docs/limitations.md).
|
|
529
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
|
+
|
|
530
513
|
## Key functions and objects
|
|
531
514
|
|
|
532
515
|
```python
|
|
@@ -555,8 +538,8 @@ class AsyncExecutor: # run_command(s), wait, join, stop, cleanup, get_results, g
|
|
|
555
538
|
|
|
556
539
|
The module also bundles a few terminal/formatting helpers used internally and
|
|
557
540
|
reusable on their own: `pretty_format_table`, `parseTable`, `print_progress_bar`,
|
|
558
|
-
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown
|
|
559
|
-
`slugify`.
|
|
541
|
+
`format_bytes`, `get_terminal_size`, `input_with_timeout_and_countdown` (its prompt and countdown go to
|
|
542
|
+
stderr), and `slugify`.
|
|
560
543
|
|
|
561
544
|
## Platform support
|
|
562
545
|
|
|
@@ -576,6 +559,43 @@ pytest -m "not slow" # skip intentional sleep-heavy cases
|
|
|
576
559
|
|
|
577
560
|
`test_expand_ranges_perf.py` is a manual performance microbenchmark and is not collected by pytest.
|
|
578
561
|
|
|
562
|
+
## Upgrading to 1.65 from 1.64
|
|
563
|
+
|
|
564
|
+
- Nothing needs doing for `mcmd`, which is unchanged. hpcp users upgrade hpcp to 9.92 before or with multiCMD 1.65: hpcp up
|
|
565
|
+
to 9.91 takes the `0` below as a size where 1.64 stopped with a `TypeError`, and 9.92 refuses a size with a unit it cannot
|
|
566
|
+
read before anything is touched.
|
|
567
|
+
- Changed, library: `format_bytes()` given a string with a unit it does not know (`'5 foo'`) returns `0` and writes the
|
|
568
|
+
"Invalid size format" line to stderr, as for a string with no number (1.64: `None`). A program that cannot tell this `0`
|
|
569
|
+
from a real one checks the string itself.
|
|
570
|
+
- Changed, library: `input_with_timeout_and_countdown()` counts an ended stdin (Ctrl-D, `/dev/null`), a closed one or none
|
|
571
|
+
as no answer: it returns `None` when the countdown ends, never sooner (1.64: an exception). It goes on asking meanwhile,
|
|
572
|
+
so Ctrl-C still aborts and a line typed before the end is taken. A program that caught `EOFError` to skip the prompt now
|
|
573
|
+
waits the countdown out.
|
|
574
|
+
- Known, planned for 1.66 ([docs/limitations.md](docs/limitations.md)): Ctrl-D after a half-typed line stops the countdown
|
|
575
|
+
until the line is ended, and `format_bytes()` ignores text after the size (`'5Gb/s'` is 5 G).
|
|
576
|
+
|
|
577
|
+
## Upgrading to 1.64 from 1.63
|
|
578
|
+
|
|
579
|
+
- Changed, library: once the reader of stdout quit, a shown command whose output keeps coming stops its call: the call's
|
|
580
|
+
commands are stopped, its queued ones skipped and, if it waits, it raises `BrokenPipeError`, whenever it began (1.63: a
|
|
581
|
+
write that found the reader gone stopped every shown call in flight, and every later call ran unseen, so a thread pool of
|
|
582
|
+
shown calls under `prog | head` could run for ever). `mcmd` is unchanged.
|
|
583
|
+
- Changed, library: a call whose commands print nothing more, or only their last words (all within 1 s, on stdout and
|
|
584
|
+
stderr), runs them all to their end, also when a command's own header met the closed pipe: a silent `umount` in a `finally`
|
|
585
|
+
runs, `losetup --find --show` still hands over its device, and a call of commands that each print one line runs them all
|
|
586
|
+
and returns (1.63: a call in flight was stopped and raised; a later one ran unseen). A command that prints nothing more is
|
|
587
|
+
no longer stopped by another write's failure (docs/limitations.md).
|
|
588
|
+
- Changed, library: a shown dry run whose line finds the reader gone raises `BrokenPipeError` if it waits, whenever it began
|
|
589
|
+
(1.63: a dry run made after the reader quit returned).
|
|
590
|
+
- hpcp 9.89 to 9.91 cloning a disk (`-dd`) with 1.64 installed beside them: when the reader quits, a delayed `e2fsck` that
|
|
591
|
+
prints for longer than 1 s is cut, with the `tune2fs` queued after it, and its call raises before the loop devices are
|
|
592
|
+
detached, where 1.63 ran it unseen; hpcp 9.92 runs its cleanup quiet.
|
|
593
|
+
- Changed: `input_with_timeout_and_countdown()` writes its prompt and countdown to stderr, after flushing stdout, and
|
|
594
|
+
`format_bytes()` its error message (1.63: stdout, where a dead one raised `BrokenPipeError` and `> log` hid the prompt).
|
|
595
|
+
- Fix: a `sys.stdout` the program closed loses the output and every command runs (1.63: `ValueError`, and nothing ran), and
|
|
596
|
+
`multiCMD.main()` called in a program leaves no stdout watch behind (1.63: its later quiet calls still asked the pipe).
|
|
597
|
+
- Fix: a usage error with a stderr that cannot be written ends 2 on Python 3.9 and 3.10 too (1.63: 1).
|
|
598
|
+
|
|
579
599
|
## Upgrading to 1.63 from 1.62
|
|
580
600
|
|
|
581
601
|
- Nothing needs doing to upgrade, except for three kinds of library program. One that catches `ConnectionResetError` from a
|