File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 11from enum import Enum , IntEnum
22from six import iteritems
3+ from psutil import NoSuchProcess
34
45
56class XLogMethod (Enum ):
@@ -68,11 +69,15 @@ def from_process(process):
6869 ],
6970 } # yapf: disable
7071
72+ try :
73+ cmdline = '' .join (process .cmdline ())
74+ except (FileNotFoundError , ProcessLookupError , NoSuchProcess ):
75+ return ProcessType .Unknown
76+
7177 # 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 (' ' , '' )
7681
7782 for ptype in ProcessType :
7883 if cmdline .startswith (ptype .value .replace (' ' , '' )):
Original file line number Diff line number Diff line change 99import time
1010import six
1111import unittest
12+ import psutil
1213
1314import logging .config
1415
4849# NOTE: those are ugly imports
4950from testgres import bound_ports
5051from testgres .utils import PgVer
52+ from testgres .node import ProcessProxy
5153
5254
5355def pg_version_ge (version ):
@@ -965,6 +967,18 @@ def test_child_pids(self):
965967 with self .assertRaises (TestgresException ):
966968 replica .source_walsender
967969
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+
968982
969983if __name__ == '__main__' :
970984 if os .environ .get ('ALT_CONFIG' ):
You can’t perform that action at this time.
0 commit comments