(self, cmd, call_args, stdin, stdout, stderr)
| 624 | } |
| 625 | |
| 626 | def __init__(self, cmd, call_args, stdin, stdout, stderr): |
| 627 | # self.ran is used for auditing what actually ran. for example, in |
| 628 | # exceptions, or if you just want to know what was ran after the |
| 629 | # command ran |
| 630 | self.ran = " ".join([shlex_quote(str(arg)) for arg in cmd]) |
| 631 | |
| 632 | self.call_args = call_args |
| 633 | self.cmd = cmd |
| 634 | |
| 635 | self.process = None |
| 636 | self._waited_until_completion = False |
| 637 | should_wait = True |
| 638 | spawn_process = True |
| 639 | |
| 640 | # if we're using an async for loop on this object, we need to put the underlying |
| 641 | # iterable in no-block mode. however, we will only know if we're using an async |
| 642 | # for loop after this object is constructed. so we'll set it to False now, but |
| 643 | # then later set it to True if we need it |
| 644 | self._force_noblock_iter = False |
| 645 | |
| 646 | # this event is used when we want to `await` a RunningCommand. see how it gets |
| 647 | # used in self.__await__ |
| 648 | try: |
| 649 | asyncio.get_running_loop() |
| 650 | except RuntimeError: |
| 651 | self.aio_output_complete = None |
| 652 | else: |
| 653 | self.aio_output_complete = asyncio.Event() |
| 654 | |
| 655 | # this is used to track if we've already raised StopIteration, and if we |
| 656 | # have, raise it immediately again if the user tries to call next() on |
| 657 | # us. https://github.com/amoffat/sh/issues/273 |
| 658 | self._stopped_iteration = False |
| 659 | |
| 660 | # with contexts shouldn't run at all yet, they prepend |
| 661 | # to every command in the context |
| 662 | if call_args["with"]: |
| 663 | spawn_process = False |
| 664 | get_prepend_stack().append(self) |
| 665 | |
| 666 | if call_args["piped"] or call_args["iter"] or call_args["iter_noblock"]: |
| 667 | should_wait = False |
| 668 | |
| 669 | if call_args["async"]: |
| 670 | should_wait = False |
| 671 | |
| 672 | # we're running in the background, return self and let us lazily |
| 673 | # evaluate |
| 674 | if call_args["bg"]: |
| 675 | should_wait = False |
| 676 | |
| 677 | # redirection |
| 678 | if call_args["err_to_out"]: |
| 679 | stderr = OProc.STDOUT |
| 680 | |
| 681 | done_callback = call_args["done"] |
| 682 | if done_callback: |
| 683 | call_args["done"] = partial(done_callback, self) |
nothing calls this directly
no test coverage detected