Skip to content

Commit

Permalink
Merge pull request #148 from toebsen/fix_eth_transport_reconnect
Browse files Browse the repository at this point in the history
fix trying to restart threads when connecting multiple times
  • Loading branch information
christoph2 authored Oct 13, 2023
2 parents 6442f5e + 2a9f680 commit 3b95897
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pyxcp/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ def connect(self):
pass

def startListener(self):
if not self.listener.is_alive():
self.listener.start()
if self.listener.is_alive():
self.finishListener()
self.listener.join()

self.listener = threading.Thread(target=self.listen)
self.listener.start()

def finishListener(self):
if hasattr(self, "closeEvent"):
Expand Down
5 changes: 4 additions & 1 deletion pyxcp/transport/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def connect(self):
self.status = 1 # connected

def startListener(self):
super().startListener()
if self._packet_listener.is_alive():
self._packet_listener.join()
self._packet_listener = threading.Thread(target=self._packet_listen)
self._packet_listener.start()
self.listener.start()

def close(self):
"""Close the transport-layer connection and event-loop."""
Expand Down
5 changes: 4 additions & 1 deletion pyxcp/transport/usb_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def connect(self):
self.status = 1 # connected

def startListener(self):
super().startListener()
if self._packet_listener.is_alive():
self._packet_listener.join()
self._packet_listener = threading.Thread(target=self._packet_listen)
self._packet_listener.start()
self.listener.start()

def close(self):
"""Close the transport-layer connection and event-loop."""
Expand Down

0 comments on commit 3b95897

Please sign in to comment.