INNER CODE UNIT · Python
connect_stream
baileydanseglio/thetadata-python · thetadata/client.py:365
def connect_stream(self, callback) -> Thread:
"""Initiate a connection with the Theta Terminal Stream server.
Requests can only be made inside this generator aka the `with client.connect_stream()` block.
Responses to the provided callback method are recycled, meaning that if you send data received
in the callback method to another thread, you must create a copy of it first.
:raises ConnectionRefusedError: If the connection failed.
:raises TimeoutError: If the timeout is set and has been reached.
:return: The thread that is responsible for receiving messages.
"""
for i in range(15):
try:
self._stream_server = socket.socket()
self._stream_server.connect((self.host, self.streaming_port))
self._stream_server.settimeout(1)
break
except ConnectionError:
if i == 14: