File tree 2 files changed +23
-4
lines changed
2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 1
1
from enum import Enum , IntEnum
2
2
from six import iteritems
3
+ from psutil import NoSuchProcess
3
4
4
5
5
6
class XLogMethod (Enum ):
@@ -68,11 +69,15 @@ def from_process(process):
68
69
],
69
70
} # yapf: disable
70
71
72
+ try :
73
+ cmdline = '' .join (process .cmdline ())
74
+ except (FileNotFoundError , ProcessLookupError , NoSuchProcess ):
75
+ return ProcessType .Unknown
76
+
71
77
# we deliberately cut special words and spaces
72
- cmdline = '' .join (process .cmdline ()) \
73
- .replace ('postgres:' , '' , 1 ) \
74
- .replace ('bgworker:' , '' , 1 ) \
75
- .replace (' ' , '' )
78
+ cmdline = cmdline .replace ('postgres:' , '' , 1 ) \
79
+ .replace ('bgworker:' , '' , 1 ) \
80
+ .replace (' ' , '' )
76
81
77
82
for ptype in ProcessType :
78
83
if cmdline .startswith (ptype .value .replace (' ' , '' )):
Original file line number Diff line number Diff line change 9
9
import time
10
10
import six
11
11
import unittest
12
+ import psutil
12
13
13
14
import logging .config
14
15
48
49
# NOTE: those are ugly imports
49
50
from testgres import bound_ports
50
51
from testgres .utils import PgVer
52
+ from testgres .node import ProcessProxy
51
53
52
54
53
55
def pg_version_ge (version ):
@@ -965,6 +967,18 @@ def test_child_pids(self):
965
967
with self .assertRaises (TestgresException ):
966
968
replica .source_walsender
967
969
970
+ def test_child_process_dies (self ):
971
+ # test for FileNotFound exception during child_processes() function
972
+ with subprocess .Popen (["sleep" , "60" ]) as process :
973
+ self .assertEqual (process .poll (), None )
974
+ # collect list of processes currently running
975
+ children = psutil .Process (os .getpid ()).children ()
976
+ # kill a process, so received children dictionary becomes invalid
977
+ process .kill ()
978
+ process .wait ()
979
+ # try to handle children list -- missing processes will have ptype "ProcessType.Unknown"
980
+ [ProcessProxy (p ) for p in children ]
981
+
968
982
969
983
if __name__ == '__main__' :
970
984
if os .environ .get ('ALT_CONFIG' ):
You can’t perform that action at this time.
0 commit comments