aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/util/processtimer.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-04-29 11:18:49 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-04-29 15:56:58 +0200
commit6d2af409eedee377b3c2ba0cd8156b9409fabd9d (patch)
tree660f8fd87f77c1030cf97cc65345b9a941a321e4 /sources/pyside6/tests/util/processtimer.py
parent88fff87519e741a3a999b8c1545834d116859faa (diff)
Tests: Fix some space-related flake8 warnings
Change-Id: I9b0ad08839bf1246620c557ec304dfa90882907b Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/tests/util/processtimer.py')
-rw-r--r--sources/pyside6/tests/util/processtimer.py71
1 files changed, 37 insertions, 34 deletions
diff --git a/sources/pyside6/tests/util/processtimer.py b/sources/pyside6/tests/util/processtimer.py
index 067f1d29c..35102e592 100644
--- a/sources/pyside6/tests/util/processtimer.py
+++ b/sources/pyside6/tests/util/processtimer.py
@@ -28,50 +28,53 @@
##
#############################################################################
-import time,os
+import os
+import time
+
class TimeoutException(Exception):
- def __init__(self, msg):
- self.msg = msg
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __str__(self):
+ return repr(self.msg)
- def __str__(self):
- return repr(self.msg)
class ProcessTimer(object):
- '''Timeout function for controlling a subprocess.Popen instance.
+ '''Timeout function for controlling a subprocess.Popen instance.
- Naive implementation using busy loop, see later other means
- of doing this.
- '''
+ Naive implementation using busy loop, see later other means
+ of doing this.
+ '''
- def __init__(self, proc, timeout):
- self.proc = proc
- self.timeout = timeout
+ def __init__(self, proc, timeout):
+ self.proc = proc
+ self.timeout = timeout
- def waitfor(self):
- time_passed = 0
- while(self.proc.poll() is None and time_passed < self.timeout):
- time_passed = time_passed + 1
- time.sleep(1)
+ def waitfor(self):
+ time_passed = 0
+ while(self.proc.poll() is None and time_passed < self.timeout):
+ time_passed = time_passed + 1
+ time.sleep(1)
- if time_passed >= self.timeout:
- raise TimeoutException("Timeout expired, possible deadlock")
+ if time_passed >= self.timeout:
+ raise TimeoutException("Timeout expired, possible deadlock")
-if __name__ == "__main__":
- #simple example
- from subprocess import Popen
+if __name__ == "__main__":
+ # simple example
- proc = Popen(['sleep','10'])
- t = ProcessTimer(proc,5)
- try:
- t.waitfor()
- except TimeoutException:
- print(f"timeout - PID: {t.proc.pid}")
- #TODO: detect SO and kill accordingly
- #Linux
- os.kill(t.proc.pid, 9)
- #Windows (not tested)
- #subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True)
- print(f"exit code: {t.proc.poll()}")
+ from subprocess import Popen
+ proc = Popen(['sleep', '10'])
+ t = ProcessTimer(proc, 5)
+ try:
+ t.waitfor()
+ except TimeoutException:
+ print(f"timeout - PID: {t.proc.pid}")
+ #TODO: detect SO and kill accordingly
+ #Linux
+ os.kill(t.proc.pid, 9)
+ #Windows (not tested)
+ #subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True)
+ print(f"exit code: {t.proc.poll()}")