You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The states are stored in the `ElectrumSocket.state` property. The Constructor of the `ElectrumSocket` is hardly doing more than just setting up the `_monitor_thread` which is an endless loop going through these states:
238
+
* `creating_sockets` will create the sockets and pass to `creating_threads` or to `broken_creating_sockets` if that fails
239
+
* `broken_creating_sockets` will try to create the socket and sleep for some time if that fails (and endlessly try to do that)
240
+
* `creating_threads` will create the write/recv/ping/notify threads and start them
241
+
* `execute_recreation_callback` will call that callback after setting the status to `ok`
242
+
* the `ok` state will now simply check the other thready and if one of them is no longer alive (probably the ping-thread as he will exit if ping fails for 4 times) it will transition to `broken_killing_threads`
243
+
* `broken_killing_threads` will set `self.running` to false and wait for the threads to terminate. Especially the `recv` thread might not terminate until he get internet connection (again). This might take forever. If all threads are terminated, it will transition to `creating_socket`
159
244
160
-
Returns:
161
-
None
162
245
"""
163
246
164
247
self.status="creating_socket"
@@ -244,7 +327,7 @@ def _monitor_loop(self):
244
327
) # to prevent high cpu load if this exception will occur endlessly
245
328
246
329
@property
247
-
defthread_status(self):
330
+
defthread_status(self)->dict:
248
331
"""Returning a handy dict containing all informations about the current
249
332
thread_status.
250
333
e.g.:
@@ -285,9 +368,6 @@ def thread_status(self):
285
368
def_write_loop(self):
286
369
"""
287
370
The loop function for writing requests to the Electrum server.
288
-
289
-
Returns:
290
-
None
291
371
"""
292
372
sleep=self.sleep_write_loop
293
373
whileself.running:
@@ -315,8 +395,25 @@ def recv_loop(self):
315
395
None
316
396
"""
317
397
sleep=self.sleep_recv_loop# This probably heavily impacts the sync-time
398
+
read_counter=0
399
+
timeout_counter=0
318
400
whileself.running:
319
-
data=self._socket.recv(2048)
401
+
try:
402
+
data=self._socket.recv(2048)
403
+
read_counter+=1
404
+
exceptTimeoutError:
405
+
pass
406
+
# This might happen quite often as we're using a non-blocking socket here.
407
+
# And if no data is there to read from and the timeout is reached, we'll
408
+
# get this error. However it's not a real error-condition (imho)
409
+
410
+
# As i'm not 100% sure about that stuff, i'll keep that code around to uncomment any time:
411
+
# timeout_counter += 1
412
+
# logger.error(
413
+
# f"Timeout in recv-loop, happens in {timeout_counter}/{read_counter} * 100 = {timeout_counter/read_counter * 100 }% of all reads. "
414
+
# )
415
+
# logger.error(f"consider to increase socket_timeout which is currently {self._socket_timeout}")
416
+
320
417
whilenotdata.endswith(b"\n"): # b"\n" is the end of the message
321
418
data+=self._socket.recv(2048)
322
419
# data looks like this:
@@ -352,7 +449,7 @@ def _ping_loop(self):
352
449
exceptElSockTimeoutExceptionase:
353
450
tries=tries+1
354
451
logger.error(
355
-
f"Error in ping-loop ({tries}th time, next try in {self.sleep_ping_loop} seconds if threshold not met"
452
+
f"Timeout in ping-loop ({tries}th time, next try in {self.sleep_ping_loop} seconds if threshold not met"
356
453
)
357
454
iftries>self.tries_threshold:
358
455
logger.error(
@@ -378,17 +475,20 @@ def notify(self, data):
378
475
else:
379
476
logger.debug("Notification:", data)
380
477
381
-
defcall(self, method, params=[]):
478
+
defcall(self, method, params=[])->dict:
382
479
"""
383
480
Calls a method on the Electrum server and returns the response.
384
481
385
482
Args:
386
483
- method (str): The name of the method to call on the Electrum server.
387
484
- *params: The parameters to pass to the method.
388
-
- timeout (float): The timeout for the request. If not specified, the default timeout of the ElectrumSocket instance will be used.
485
+
389
486
390
487
Returns:
391
488
dict: The response from the Electrum server.
489
+
490
+
might raise a ElSockTimeoutException if self._call_timeout is over
0 commit comments