File tree 2 files changed +15
-1
lines changed 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
- from .watcher import PostgresqlWatcher
1
+ from .watcher import PostgresqlWatcher , PostgresqlWatcherChannelSubscriptionTimeoutError
Original file line number Diff line number Diff line change @@ -111,11 +111,15 @@ def start(self):
111
111
self .subscription_proces .start ()
112
112
# And wait for the Process to be ready to listen for updates
113
113
# from PostgreSQL
114
+ timeout = 20 # seconds
115
+ timeout_time = time () + timeout
114
116
while True :
115
117
if self .parent_conn .poll ():
116
118
message = int (self .parent_conn .recv ())
117
119
if message == _ChannelSubscriptionMessage .IS_READY :
118
120
break
121
+ if time () > timeout_time :
122
+ raise PostgresqlWatcherChannelSubscriptionTimeoutError (timeout )
119
123
sleep (1 / 1000 ) # wait for 1 ms
120
124
121
125
def _cleanup_connections_and_processes (self ) -> None :
@@ -175,3 +179,13 @@ def should_reload(self) -> bool:
175
179
self ._create_subscription_process (delay = 10 )
176
180
177
181
return False
182
+
183
+
184
+ class PostgresqlWatcherChannelSubscriptionTimeoutError (RuntimeError ):
185
+ """
186
+ Raised if the channel subscription could not be established within a given timeout.
187
+ """
188
+
189
+ def __init__ (self , timeout_in_seconds : float ) -> None :
190
+ msg = f"The channel subscription could not be established within { timeout_in_seconds :.0f} seconds."
191
+ super ().__init__ (msg )
You can’t perform that action at this time.
0 commit comments