1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 from python_qt_binding.QtCore import QObject, Signal
34 import subprocess
35 import threading
36
37 from .detailed_msg_box import MessageBox
41 '''
42 The class overrides the subprocess.Popen and waits in a thread for its finish.
43 If an error is printed out, it will be shown in a message dialog.
44 '''
45 error = Signal(str, str, str)
46 '''@ivar: the signal is emitted if error output was detected (id, decription, message)'''
47
48 finished = Signal(str)
49 '''@ivar: the signal is emitted on exit (id)'''
50
51 - def __init__(self, args, bufsize=0, executable=None, stdin=None, stdout=None,
52 stderr=subprocess.PIPE, preexec_fn=None, close_fds=False,
53 shell=False, cwd=None, env=None, universal_newlines=False,
54 startupinfo=None, creationflags=0, object_id='', description=''):
55 '''
56 For arguments see https://docs.python.org/2/library/subprocess.html
57 Additional arguments:
58 :param object_id: the identification string of this object and title of the
59 error message dialog
60 :type object_id: str
61 :param description: the description string used as addiotional information
62 in dialog if an error was occured
63 :type description: str
64 '''
65 try:
66 QObject.__init__(self)
67 self._args = args
68 self._object_id = object_id
69 self._description = description
70 self.error.connect(self.on_error)
71
72 self.popen = subprocess.Popen(args=args, bufsize=bufsize, executable=executable, stdin=stdin, stdout=stdout,
73 stderr=stderr, preexec_fn=preexec_fn, close_fds=close_fds, shell=shell, cwd=cwd, env=env,
74 universal_newlines=universal_newlines, startupinfo=startupinfo, creationflags=creationflags)
75 thread = threading.Thread(target=self._supervise)
76 thread.setDaemon(True)
77 thread.start()
78 except Exception as _:
79 raise
80
81
82
83
84 @property
87
88 @property
91
92 @property
94 return self.popen.stdin
95
97 '''
98 Wait for process to avoid 'defunct' processes
99 '''
100 self.popen.wait()
101 result_err = ''
102 if self.stderr is not None:
103 result_err = self.stderr.read()
104 if result_err:
105 self.error.emit(self._object_id, self._description, result_err)
106 self.finished.emit(self._object_id)
107
108 - def on_error(self, object_id, descr, msg):
111