From 9e16529e445eaed92a72a1510cfa83582179d079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alin=20Tr=C4=83istaru?= Date: Tue, 25 Apr 2017 11:33:19 +0300 Subject: [PATCH] further reduce CPU usage --- scripts/_7zip.py | 16 ++++------------ scripts/imager.py | 3 ++- scripts/install.py | 2 ++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/scripts/_7zip.py b/scripts/_7zip.py index c802f07..5fa5723 100644 --- a/scripts/_7zip.py +++ b/scripts/_7zip.py @@ -47,20 +47,12 @@ def extract_iso(src, dst, pattern=None, suppress_out=True): if pattern is None: _cmd = _7zip + cli_option + ' x -y -o' + gen.quote(dst) + ' ' + gen.quote(src) + suppress_out else: - _cmd = _7zip + ' -y x ' + gen.quote(src) + ' -o' + dst + ' ' + gen.quote(pattern) + ' -r' + suppress_out + _cmd = _7zip + ' x -y ' + gen.quote(src) + ' -o' + dst + ' ' + gen.quote(pattern) + ' -r' + suppress_out gen.log('Executing ==> ' + _cmd) - _7zip_process = subprocess.Popen(_cmd, universal_newlines=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, - stdout=subprocess.PIPE, shell=True) + config.status_text = 'Status: Extracting ' + os.path.basename(src).strip() - while True: - line = _7zip_process.stdout.readline() - # gen.log(line) - if line.startswith('- '): - config.status_text = 'Status: Extracting ' + line[2:].strip() - elif platform.system() == 'Linux': # line.startswith('Extracting'): # Under Linux it prints directly all the process (may be due to version diff). - config.status_text = 'Status: ' + line.strip() - if line == '' and _7zip_process.poll() != None: - break + with open(os.devnull, 'w') as devnull: + subprocess.call(_cmd, stdin=devnull, stdout=devnull, stderr=devnull, shell=True) def list_iso(iso_link, suppress_out=True): diff --git a/scripts/imager.py b/scripts/imager.py index 24c9a67..46df57a 100644 --- a/scripts/imager.py +++ b/scripts/imager.py @@ -48,10 +48,11 @@ def dd_linux(): ).start() while dd_process.poll() is None: - time.sleep(1) # If this time delay is not given, the Popen does not execute the actual command + time.sleep(0.1) # If this time delay is not given, the Popen does not execute the actual command dd_process.send_signal(signal.SIGUSR1) dd_process.stderr.flush() while True: + time.sleep(0.1) out_error = dd_process.stderr.readline().decode() if out_error: if 'bytes' in out_error: diff --git a/scripts/install.py b/scripts/install.py index 0506cdd..3d56b02 100644 --- a/scripts/install.py +++ b/scripts/install.py @@ -12,6 +12,7 @@ import sys import platform import threading import subprocess +import time from .usb import * from .gen import * # from .iso import * @@ -146,6 +147,7 @@ def install_progress(): percentage = 100 config.percentage = percentage pbar.update(percentage) + time.sleep(0.1) def install_patch():