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

Commit0f842fd

Browse files
PostgresNodePortManager__ThisHost is defined (was: PostgresNodePortManager__Global)
It is a singleton.
1 parentef095d3 commit0f842fd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

‎testgres/node.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# coding: utf-8
2+
from __future__importannotations
3+
24
importlogging
35
importos
46
importrandom
@@ -133,6 +135,9 @@ def __repr__(self):
133135

134136

135137
classPostgresNodePortManager:
138+
def__init__(self):
139+
super().__init__()
140+
136141
defreserve_port(self)->int:
137142
raiseNotImplementedError("PostManager::reserve_port is not implemented.")
138143

@@ -141,10 +146,24 @@ def release_port(self, number: int) -> None:
141146
raiseNotImplementedError("PostManager::release_port is not implemented.")
142147

143148

144-
classPostgresNodePortManager__Global(PostgresNodePortManager):
149+
classPostgresNodePortManager__ThisHost(PostgresNodePortManager):
150+
sm_single_instance:PostgresNodePortManager=None
151+
sm_single_instance_guard=threading.Lock()
152+
145153
def__init__(self):
146154
pass
147155

156+
def__new__(cls)->PostgresNodePortManager:
157+
assert__class__==PostgresNodePortManager__ThisHost
158+
assert__class__.sm_single_instance_guardisnotNone
159+
160+
if__class__.sm_single_instanceisNone:
161+
with__class__.sm_single_instance_guard:
162+
__class__.sm_single_instance=super().__new__(cls)
163+
assert__class__.sm_single_instance
164+
asserttype(__class__.sm_single_instance)==__class__# noqa: E721
165+
return__class__.sm_single_instance
166+
148167
defreserve_port(self)->int:
149168
returnutils.reserve_port()
150169

@@ -290,7 +309,7 @@ def _get_port_manager(os_ops: OsOperations) -> PostgresNodePortManager:
290309
assertisinstance(os_ops,OsOperations)
291310

292311
# [2025-04-03] It is our old, incorrected behaviour
293-
returnPostgresNodePortManager__Global()
312+
returnPostgresNodePortManager__ThisHost()
294313

295314
defclone_with_new_name_and_base_dir(self,name:str,base_dir:str):
296315
assertnameisNoneortype(name)==str# noqa: E721

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp