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

Commita92a6e7

Browse files
Merge remote-tracking branch 'origin/D20250227_001--node-pid' into D20250226_001--ci_and_ssh
2 parents381d64d +fce595a commita92a6e7

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

‎testgres/node.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class PostgresNode(object):
132132
# a max number of node start attempts
133133
_C_MAX_START_ATEMPTS=5
134134

135+
# a max number of read pid file attempts
136+
_C_MAX_GET_PID_ATEMPTS=5
137+
135138
def__init__(self,name=None,base_dir=None,port=None,conn_params:ConnectionParams=ConnectionParams(),
136139
bin_dir=None,prefix=None):
137140
"""
@@ -208,14 +211,40 @@ def pid(self):
208211
Return postmaster's PID if node is running, else 0.
209212
"""
210213

211-
ifself.status():
212-
pid_file=os.path.join(self.data_dir,PG_PID_FILE)
213-
lines=self.os_ops.readlines(pid_file)
214-
pid=int(lines[0])iflineselseNone
215-
returnpid
214+
nAttempt=0
215+
pid_file=os.path.join(self.data_dir,PG_PID_FILE)
216+
pid_s:str=None
217+
whileTrue:
218+
ifnAttempt==__class__._C_MAX_GET_PID_ATEMPTS:
219+
errMsg="Can't read postmaster pid file [{0}].".format(pid_file)
220+
raiseException(errMsg)
216221

217-
# for clarity
218-
return0
222+
nAttempt+=1
223+
224+
s1=self.status()
225+
ifs1!=NodeStatus.Running:
226+
return0
227+
228+
try:
229+
lines=self.os_ops.readlines(pid_file)
230+
exceptException:
231+
s2=self.status()
232+
ifs2==NodeStatus.Running:
233+
raise
234+
return0
235+
236+
assertlinesisnotNone# [2025-02-27] OK?
237+
asserttype(lines)==list# noqa: E721
238+
iflen(lines)==0:
239+
continue
240+
241+
pid_s=lines[0]
242+
asserttype(pid_s)==str# noqa: E721
243+
iflen(pid_s)==0:
244+
continue
245+
246+
pid=int(pid_s)
247+
returnpid
219248

220249
@property
221250
defauxiliary_pids(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp