Skip to content

Commit

Permalink
moulti run: fix crash when passing a non-executable script.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierog committed Jan 11, 2025
1 parent f552c87 commit 27a2771
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Although Moulti's Python packages, modules and functions are obviously available

- diff, load, manpage, step delete: improve pipelining so as to prevent deadlocks
- server-side networking: use non-blocking methods to deal with non-blocking sockets
- `moulti run path/to/non_executable_script` used to crash

## [1.28.0] - 2024-12-29

Expand Down
5 changes: 3 additions & 2 deletions src/moulti/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ def exec(self, command: list[str]) -> None:
worker = get_current_worker()
harvest_output = self.output_policy() # Harvest stdout/stderr lines
output_delegated = False
output_selector = None
process = None
try:
self.init_command_running = True
original_command = command.copy()
Expand All @@ -417,7 +419,6 @@ def exec(self, command: list[str]) -> None:
process = subprocess.Popen(command, **popen_args, **self.output_policy_popen_args())
self.logconsole(f'exec: {command} launched with PID {process.pid}')
returncode = None
output_selector = None
if harvest_output:
output_selector = selectors.DefaultSelector()
assert process.stdout is not None # for mypy
Expand Down Expand Up @@ -451,7 +452,7 @@ def exec(self, command: list[str]) -> None:
self.init_command_running = False
finally:
clean_selector(output_selector, close_fds=False, close=True)
if harvest_output and not output_delegated and process.stdout is not None:
if harvest_output and not output_delegated and process is not None and process.stdout is not None:
self.logconsole(f'exec: no output harvested, closing child process stdout fd {process.stdout.fileno()}')
process.stdout.close()

Expand Down

0 comments on commit 27a2771

Please sign in to comment.