1
1
# coding: utf-8
2
+ from __future__import annotations
3
+
2
4
import logging
3
5
import os
4
6
import random
@@ -133,6 +135,9 @@ def __repr__(self):
133
135
134
136
135
137
class PostgresNodePortManager :
138
+ def __init__ (self ):
139
+ super ().__init__ ()
140
+
136
141
def reserve_port (self )-> int :
137
142
raise NotImplementedError ("PostManager::reserve_port is not implemented." )
138
143
@@ -141,10 +146,24 @@ def release_port(self, number: int) -> None:
141
146
raise NotImplementedError ("PostManager::release_port is not implemented." )
142
147
143
148
144
- class PostgresNodePortManager__Global (PostgresNodePortManager ):
149
+ class PostgresNodePortManager__ThisHost (PostgresNodePortManager ):
150
+ sm_single_instance :PostgresNodePortManager = None
151
+ sm_single_instance_guard = threading .Lock ()
152
+
145
153
def __init__ (self ):
146
154
pass
147
155
156
+ def __new__ (cls )-> PostgresNodePortManager :
157
+ assert __class__ == PostgresNodePortManager__ThisHost
158
+ assert __class__ .sm_single_instance_guard is not None
159
+
160
+ if __class__ .sm_single_instance is None :
161
+ with __class__ .sm_single_instance_guard :
162
+ __class__ .sm_single_instance = super ().__new__ (cls )
163
+ assert __class__ .sm_single_instance
164
+ assert type (__class__ .sm_single_instance )== __class__ # noqa: E721
165
+ return __class__ .sm_single_instance
166
+
148
167
def reserve_port (self )-> int :
149
168
return utils .reserve_port ()
150
169
@@ -290,7 +309,7 @@ def _get_port_manager(os_ops: OsOperations) -> PostgresNodePortManager:
290
309
assert isinstance (os_ops ,OsOperations )
291
310
292
311
# [2025-04-03] It is our old, incorrected behaviour
293
- return PostgresNodePortManager__Global ()
312
+ return PostgresNodePortManager__ThisHost ()
294
313
295
314
def clone_with_new_name_and_base_dir (self ,name :str ,base_dir :str ):
296
315
assert name is None or type (name )== str # noqa: E721