Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Remove useless thread
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Nov 23, 2018
1 parent 7a37410 commit f4fd741
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
12 changes: 4 additions & 8 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,27 @@ def __init__(self, port='auto', path='~/.zigate.json',
self._ieee = None
self._started = False

self._packets = queue.Queue()
self._event_thread = threading.Thread(target=self._event_loop,
name='ZiGate-Event Loop')
self._event_thread.setDaemon(True)
self._event_thread.start()

dispatcher.connect(self._packet_received, ZIGATE_PACKET_RECEIVED)
dispatcher.connect(self.interpret_response, ZIGATE_RESPONSE_RECEIVED)
# dispatcher.connect(self.decode_data, ZIGATE_PACKET_RECEIVED)

if auto_start:
self.autoStart()
if auto_save:
self.start_auto_save()

def _event_loop(self):
while True:
if not self._packets.empty():
packet = self._packets.get()
if self.connection and not self.connection.received.empty():
packet = self.connection.received.get()
dispatch_signal(ZIGATE_PACKET_RECEIVED, self, packet=packet)
self.decode_data(packet)
else:
sleep(SLEEP_INTERVAL)

def _packet_received(self, packet):
self._packets.put(packet)

def setup_connection(self):
self.connection = ThreadSerialConnection(self, self._port)

Expand Down
11 changes: 2 additions & 9 deletions zigate/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(self, device, port=None):
self._port = port
self.device = device
self.queue = queue.Queue()
self.received = queue.Queue()
self._running = True
self.reconnect()
# self.serial = self.initSerial()
self.thread = threading.Thread(target=self.listen,
name='ZiGate-Listen')
self.thread.setDaemon(True)
Expand Down Expand Up @@ -64,9 +64,6 @@ def reconnect(self):
delay *= 2
return self.serial

def packet_received(self, raw_message):
dispatcher.send(ZIGATE_PACKET_RECEIVED, packet=raw_message)

def read_data(self, data):
'''
Read ZiGate output and split messages
Expand All @@ -77,11 +74,7 @@ def read_data(self, data):
while endpos != -1:
startpos = self._buffer.find(b'\x01')
raw_message = self._buffer[startpos:endpos + 1]
# print(raw_message)
threading.Thread(target=self.packet_received,
args=(raw_message,),
name='ZiGate-Packet Received'
).start()
self.received.put(raw_message)
self._buffer = self._buffer[endpos + 1:]
endpos = self._buffer.find(b'\x03')

Expand Down

0 comments on commit f4fd741

Please sign in to comment.