File: TransRead-kill-subprocesses.patch

package info (click to toggle)
bmap-tools 3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 936 kB
  • sloc: python: 5,078; sh: 117; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Date: Wed, 10 Mar 2021 14:09:34 +0200
Subject: TransRead: kill subprocesses

Kill and wait for subprocesses when destroying TransRead objects. This
gets rid of the following warning (observed when running self-tests):

/usr/lib64/python3.9/subprocess.py:1048: ResourceWarning: subprocess 140912 is still running
  _warn("subprocess %s is still running" % self.pid,

Origin: upstream, 3.7, commit:d17e2eaea318444c7370298739da3c5a3969cc6d
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 bmaptools/TransRead.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py
index da3c8b5..1d0b582 100644
--- a/bmaptools/TransRead.py
+++ b/bmaptools/TransRead.py
@@ -188,14 +188,21 @@ class TransRead(object):
         """The class destructor which closes opened files."""
         self._done = True
 
-        for child in self._child_processes:
-            child.kill()
+        if getattr(self, "_f_objs"):
+            for file_obj in self._f_objs:
+                file_obj.close()
+            self._f_objs = None
 
-        if self._rthread:
+        if getattr(self, "_rthread"):
             self._rthread.join()
-
-        for file_obj in self._f_objs:
-            file_obj.close()
+            self._rthread = None
+
+        if getattr(self, "_child_processes"):
+            for child in self._child_processes:
+                if child.poll() is None:
+                    child.kill()
+                    child.wait()
+            self._child_processes = []
 
     def _read_thread(self, f_from, f_to):
         """