-
Notifications
You must be signed in to change notification settings - Fork 87
Use pure python code in place of os.system #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
a1f7b08
to
3782f97
Compare
3782f97
to
5149284
Compare
5149284
to
2c59a22
Compare
scripts/import_srpm.py
Outdated
raise ValueError("All commands in the list must be non-empty.") | ||
|
||
processes: list[subprocess.Popen[bytes]] = [] | ||
last_process_stdout = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming it next_process_stdin
would make it more accurate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it depends on which side of the pipe you're looking at 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in one way yes, but I'm rather seeing it as "in one case the name is always valid, while in the other there is no previous process when launching the first one"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it's a IO[bytes] | None
.
But I'm also ok with the other name, I'll use it 👍
scripts/import_srpm.py
Outdated
# to prevent deadlocks if the current process finishes before the previous one. | ||
if last_process_stdout: | ||
last_process_stdout.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure of the nature of the deadlock, but avoiding keeping 2 readers on the pipe is definitely a good idea. Maybe describe it like "the new process does the reading from this pipe, drop our ref to it, notably preventing deadlocks"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote that based on an example I found, but I can't produce any deadlock, and I find plenty of examples that don't use it. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be kept, as explained (much better) in the API doc
scripts/import_srpm.py
Outdated
for i, p in enumerate(processes): | ||
p.wait() | ||
if p.returncode != 0: | ||
raise subprocess.CalledProcessError(returncode=p.returncode, cmd=commands[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more clear with for cmd, p in zip(commands, processes)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
os.system calls the user's shell, and is not directly checking for errors. This should raise an error when cpio or rpm2cpio fail, or if they can't be found. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
2c59a22
to
fa8bab3
Compare
os.system calls the user's shell, and is not directly checking for errors. This should raise an error when cpio or rpm2cpio fail, or if they can't be found.