Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit28d5a4e

Browse files
author
Sofia Kopikova
committed
Catch FileNotFoundError exception
When we want to find some Postgres process in testgres psutils lib first gets list of all system processes (children() function in testgres's auxiliary_processes). Next testgres asks for process name (cmdline() function), so psutils goes to /proc/pid/ in Linux. In case any of processes listed in previous step, we get FileNotFoundError
1 parentceb1ee9 commit28d5a4e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

‎testgres/enums.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fromenumimportEnum,IntEnum
22
fromsiximportiteritems
3+
frompsutilimportNoSuchProcess
34

45

56
classXLogMethod(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+
returnProcessType.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
forptypeinProcessType:
7883
ifcmdline.startswith(ptype.value.replace(' ','')):

‎tests/test_simple.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
importtime
1010
importsix
1111
importunittest
12+
importpsutil
1213

1314
importlogging.config
1415

@@ -48,6 +49,7 @@
4849
# NOTE: those are ugly imports
4950
fromtestgresimportbound_ports
5051
fromtestgres.utilsimportPgVer
52+
fromtestgres.nodeimportProcessProxy
5153

5254

5355
defpg_version_ge(version):
@@ -965,6 +967,17 @@ def test_child_pids(self):
965967
withself.assertRaises(TestgresException):
966968
replica.source_walsender
967969

970+
deftest_child_process_dies(self):
971+
# test for FileNotFound exception during child_processes() function
972+
withsubprocess.Popen(["sleep","60"])asprocess:
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)forpinchildren]
968981

969982
if__name__=='__main__':
970983
ifos.environ.get('ALT_CONFIG'):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp