Skip to content

Commit

Permalink
Add @connected property to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
danijar committed Aug 14, 2024
1 parent 8bbeccb commit 1d58a44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zerofun/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.2.0'
__version__ = '2.3.0'

import multiprocessing as mp
try:
Expand Down
7 changes: 7 additions & 0 deletions zerofun/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ def __init__(
self.conn_per_sec = elements.FPS()
self.send_per_sec = elements.FPS()
self.recv_per_sec = elements.FPS()
self._connected = False
connect and self.connect()

@property
def connected(self):
return self._connected

def __getattr__(self, name):
if name.startswith('__'):
raise AttributeError(name)
Expand Down Expand Up @@ -65,6 +70,7 @@ def connect(self, retry=True, timeout=10):
self.socket.connect(self.resolved, timeout)
self._print('Connection established')
self.conn_per_sec.step(1)
self._connected = True
return
except sockets.ProtocolError as e:
self._print(f'Ignoring unexpected message: {e}')
Expand Down Expand Up @@ -125,6 +131,7 @@ def _listen(self):
self.recv_per_sec.step(1)
return result
except sockets.NotAliveError:
self._connected = False
self._print('Lost connection to server')
if self.reconnect:
self.connect()
Expand Down

0 comments on commit 1d58a44

Please sign in to comment.