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

Commitb5c4d7b

Browse files
PostgresNode::pid is improved
- We do multiple attempts to read pid file.- We process a case when we see that node is stopped between test and read.- We process a case when pid-file is empty.
1 parent6d67da2 commitb5c4d7b

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

‎testgres/node.py

Lines changed: 35 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,39 @@ 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+
iflen(pid_s)==0:
243+
continue
244+
245+
pid=int(pid_s)
246+
returnpid
219247

220248
@property
221249
defauxiliary_pids(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp