@@ -335,7 +335,7 @@ def connect_stream(self, callback) -> Thread:
335
335
raise ConnectionError ('Unable to connect to the local Theta Terminal Stream process. '
336
336
'Try restarting your system.' )
337
337
sleep (1 )
338
- self ._stream_server .settimeout (self . timeout )
338
+ self ._stream_server .settimeout (10 )
339
339
self ._stream_impl = callback
340
340
out = Thread (target = self ._recv_stream )
341
341
out .start ()
@@ -487,7 +487,7 @@ def _recv_stream(self):
487
487
msg = StreamMsg ()
488
488
msg .client = self
489
489
parse_int = lambda d : int .from_bytes (d , "big" )
490
-
490
+ self . _stream_server . settimeout ( 10 )
491
491
while True :
492
492
try :
493
493
msg .type = StreamMsgType .from_code (parse_int (self ._read_stream (1 )[:1 ]))
@@ -502,7 +502,6 @@ def _recv_stream(self):
502
502
msg .ohlcvc .from_bytes (data )
503
503
elif msg .type == StreamMsgType .PING :
504
504
self ._read_stream (n_bytes = 4 )
505
- continue
506
505
elif msg .type == StreamMsgType .OPEN_INTEREST :
507
506
data = self ._read_stream (n_bytes = 8 )
508
507
msg .open_interest .from_bytes (data )
@@ -516,16 +515,19 @@ def _recv_stream(self):
516
515
self ._read_stream (4 ) # Future use.
517
516
else :
518
517
raise ValueError ('undefined msg type: ' + str (msg .type ))
519
-
520
- self ._stream_impl (msg )
521
518
except ConnectionResetError :
522
519
msg .type = StreamMsgType .STREAM_DEAD
523
520
self ._stream_impl (msg )
524
521
return
522
+ except Exception as e :
523
+ msg .type = StreamMsgType .ERROR
524
+ print ('Stream error: ' + str (e ))
525
+ self ._stream_impl (msg )
525
526
526
527
def _read_stream (self , n_bytes : int ) -> bytearray :
527
528
"""from_bytes
528
529
"""
530
+
529
531
buffer = bytearray (self ._stream_server .recv (n_bytes ))
530
532
total = buffer .__len__ ()
531
533
0 commit comments