From 77a42a1df95650d5ce31b99950f085f4105873da Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 21 May 2026 12:09:33 +0000 Subject: [PATCH] tool rand2file: use `os.process_cpu_count()` to set thread count --- mmgen/tool/fileutil.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mmgen/tool/fileutil.py b/mmgen/tool/fileutil.py index b6fe0283..dcd62a3c 100755 --- a/mmgen/tool/fileutil.py +++ b/mmgen/tool/fileutil.py @@ -70,7 +70,7 @@ class tool_cmd(tool_cmd_base): os.close(f) return True - def rand2file(self, outfile: str, nbytes: str, *, threads=4, silent=False): + def rand2file(self, outfile: str, nbytes: str, *, silent=False): """ write ‘nbytes’ bytes of random data to specified file (dd-style byte specifiers supported) @@ -118,7 +118,12 @@ class tool_cmd(tool_cmd_base): key = Crypto(self.cfg).get_random(32) q1, q2 = (Queue(), Queue()) - for i in range(max(1, threads-2)): + try: + threads = os.process_cpu_count() # Python 3.13 + except AttributeError: + threads = os.cpu_count() + + for i in range(max(1, threads - 1)): t = Thread(target=encrypt_worker) t.daemon = True t.start()