Asyncore update

- shutdown fix
This commit is contained in:
Peter Šurda 2017-05-29 14:35:08 +02:00
parent bdaa939e2c
commit 0aa5dbd958
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
4 changed files with 7 additions and 5 deletions

View File

@ -21,7 +21,7 @@ class AnnounceThread(threading.Thread, StoppableThread):
def run(self): def run(self):
lastSelfAnnounced = 0 lastSelfAnnounced = 0
while not self._stopped: while not self._stopped and state.shutdown == 0:
processed = 0 processed = 0
if lastSelfAnnounced < time.time() - UDPSocket.announceInterval: if lastSelfAnnounced < time.time() - UDPSocket.announceInterval:
self.announceSelf() self.announceSelf()

View File

@ -53,7 +53,7 @@ class InvThread(threading.Thread, StoppableThread):
continue continue
if len(hashes) > 0: if len(hashes) > 0:
#print "sending inv of %i" % (len(hashes)) #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] = {} self.collectionOfInvs[iterator] = {}
iterator += 1 iterator += 1
iterator %= InvThread.size iterator %= InvThread.size

View File

@ -5,6 +5,7 @@ from debug import logger
from helper_threading import StoppableThread from helper_threading import StoppableThread
import network.asyncore_pollchoose as asyncore import network.asyncore_pollchoose as asyncore
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
import state
class BMNetworkThread(threading.Thread, StoppableThread): class BMNetworkThread(threading.Thread, StoppableThread):
def __init__(self): def __init__(self):
@ -15,10 +16,11 @@ class BMNetworkThread(threading.Thread, StoppableThread):
logger.info("init asyncore thread") logger.info("init asyncore thread")
def run(self): def run(self):
while not self._stopped: while not self._stopped and state.shutdown == 0:
BMConnectionPool().loop() BMConnectionPool().loop()
def stopThread(self): def stopThread(self):
super(BMNetworkThread, self).stopThread()
for i in BMConnectionPool().listeningSockets: for i in BMConnectionPool().listeningSockets:
try: try:
i.close() i.close()
@ -37,4 +39,3 @@ class BMNetworkThread(threading.Thread, StoppableThread):
# just in case # just in case
asyncore.close_all() asyncore.close_all()
super(BMNetworkThread, self).stopThread()

View File

@ -10,6 +10,7 @@ from inventory import Inventory
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from network.bmproto import BMProto from network.bmproto import BMProto
import protocol import protocol
import state
class ReceiveQueueThread(threading.Thread, StoppableThread): class ReceiveQueueThread(threading.Thread, StoppableThread):
def __init__(self): def __init__(self):
@ -21,7 +22,7 @@ class ReceiveQueueThread(threading.Thread, StoppableThread):
def run(self): def run(self):
lastprinted = int(time.time()) lastprinted = int(time.time())
while not self._stopped: while not self._stopped and state.shutdown == 0:
if lastprinted < int(time.time()): if lastprinted < int(time.time()):
lastprinted = int(time.time()) lastprinted = int(time.time())
processed = 0 processed = 0