From 0aa5dbd95846a8a7a746f2726c082782435ad3db Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 29 May 2017 14:35:08 +0200 Subject: [PATCH] Asyncore update - shutdown fix --- src/network/announcethread.py | 2 +- src/network/invthread.py | 2 +- src/network/networkthread.py | 5 +++-- src/network/receivequeuethread.py | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/network/announcethread.py b/src/network/announcethread.py index 29ed301e..85e69877 100644 --- a/src/network/announcethread.py +++ b/src/network/announcethread.py @@ -21,7 +21,7 @@ class AnnounceThread(threading.Thread, StoppableThread): def run(self): lastSelfAnnounced = 0 - while not self._stopped: + while not self._stopped and state.shutdown == 0: processed = 0 if lastSelfAnnounced < time.time() - UDPSocket.announceInterval: self.announceSelf() diff --git a/src/network/invthread.py b/src/network/invthread.py index a880607a..1fd4a401 100644 --- a/src/network/invthread.py +++ b/src/network/invthread.py @@ -53,7 +53,7 @@ class InvThread(threading.Thread, StoppableThread): continue if len(hashes) > 0: #print "sending inv of %i" % (len(hashes)) - connection.writeQueue.put(protocol.CreatePacket('inv', addresses.encodeVarint(len(hashes)) + b"".join(hashes))) + connection.writeQueue.put(protocol.CreatePacket('inv', addresses.encodeVarint(len(hashes)) + "".join(hashes))) self.collectionOfInvs[iterator] = {} iterator += 1 iterator %= InvThread.size diff --git a/src/network/networkthread.py b/src/network/networkthread.py index 54c58f12..7e98bcc0 100644 --- a/src/network/networkthread.py +++ b/src/network/networkthread.py @@ -5,6 +5,7 @@ from debug import logger from helper_threading import StoppableThread import network.asyncore_pollchoose as asyncore from network.connectionpool import BMConnectionPool +import state class BMNetworkThread(threading.Thread, StoppableThread): def __init__(self): @@ -15,10 +16,11 @@ class BMNetworkThread(threading.Thread, StoppableThread): logger.info("init asyncore thread") def run(self): - while not self._stopped: + while not self._stopped and state.shutdown == 0: BMConnectionPool().loop() def stopThread(self): + super(BMNetworkThread, self).stopThread() for i in BMConnectionPool().listeningSockets: try: i.close() @@ -37,4 +39,3 @@ class BMNetworkThread(threading.Thread, StoppableThread): # just in case asyncore.close_all() - super(BMNetworkThread, self).stopThread() diff --git a/src/network/receivequeuethread.py b/src/network/receivequeuethread.py index a0a2c4b8..b31b82b4 100644 --- a/src/network/receivequeuethread.py +++ b/src/network/receivequeuethread.py @@ -10,6 +10,7 @@ from inventory import Inventory from network.connectionpool import BMConnectionPool from network.bmproto import BMProto import protocol +import state class ReceiveQueueThread(threading.Thread, StoppableThread): def __init__(self): @@ -21,7 +22,7 @@ class ReceiveQueueThread(threading.Thread, StoppableThread): def run(self): lastprinted = int(time.time()) - while not self._stopped: + while not self._stopped and state.shutdown == 0: if lastprinted < int(time.time()): lastprinted = int(time.time()) processed = 0