fix: Replaced os.popen() with Python's inbuilt file handling#897
Open
S1DDHEY wants to merge 1 commit intoSeedSigner:devfrom
Open
fix: Replaced os.popen() with Python's inbuilt file handling#897S1DDHEY wants to merge 1 commit intoSeedSigner:devfrom
os.popen() with Python's inbuilt file handling#897S1DDHEY wants to merge 1 commit intoSeedSigner:devfrom
Conversation
12 tasks
PROWLERx15
reviewed
Apr 9, 2026
Contributor
PROWLERx15
left a comment
There was a problem hiding this comment.
This appears to be a straightforward cleanup to me.
Reading /proc/cpuinfo directly is simpler and more appropriate than shelling out to cat | grep for this.
I do not see any obvious issue with the change. Main thing worth confirming is the equivalence on Rasp Pi, but the approach itself looks good.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem or Issue being addressed
Resolves #856
In
tools_views.py, the entropy generation logic usesos.popen("cat /proc/cpuinfo | grep Serial")to gather the CPU serial number for mixing into the seed entropy hash.os.popen()implicitly spawns a shell, which is unnecessary here since the data can be read directly via Python's built-in file I/O.Solution
Replaced the
os.popen()call with native Python file I/O usingopen("/proc/cpuinfo", "r"). This reads the file line by line and extracts the Serial field without spawning any external processes (cat,grep) or a shell.Also removed the now-unused
import osat the top of the file, as no other code in the file depends on it.Additional Information
Serialentry (viabreak), whereas the previous os.popen approach would effectively select the last one. In practice, cpuinfo contains only a singleSerialfield, so the behavior is equivalent on all current hardware.try/exceptblock is preserved, so on non-Raspberry Pi hardware (or any system withoutcpuinfo), the code gracefully falls back tohash_bytes = b'0'as before.os.popen()is not strictly deprecated but is discouraged in favor ofsubprocess.run()or native file I/O. Since we're simply reading a local file, native file I/O is the simplest and most direct approach — no shell or subprocess needed.Screenshots
N/A
This pull request is categorized as a:
Checklist
I ran
pytestlocallyI included screenshots of any new or modified screens
Should be part of the PR description above.
I added or updated tests
Any new or altered functionality should be covered in a unit test. Any new or updated sequences require FlowTests.
I tested this PR hands-on on the following platform(s):
I have reviewed these notes:
Thank you! Please join our Devs' Telegram group to get more involved.