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

Commita7e8fcf

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 commita7e8fcf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-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: 15 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):
@@ -966,6 +968,19 @@ def test_child_pids(self):
966968
replica.source_walsender
967969

968970

971+
deftest_child_process_dies(self):
972+
# test for FileNotFound exception during child_processes() function
973+
withsubprocess.Popen(["sleep","60"])asprocess:
974+
self.assertEqual(process.poll(),None)
975+
# collect list of processes currently running
976+
children=psutil.Process(os.getpid()).children()
977+
# kill a process, so received children dictionary becomes invalid
978+
process.kill()
979+
process.wait()
980+
# try to handle children list -- missing processes will have ptype "ProcessType.Unknown"
981+
[ProcessProxy(p)forpinchildren]
982+
983+
969984
if__name__=='__main__':
970985
ifos.environ.get('ALT_CONFIG'):
971986
suite=unittest.TestSuite()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp