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):
lastSelfAnnounced = 0
while not self._stopped:
while not self._stopped and state.shutdown == 0:
processed = 0
if lastSelfAnnounced < time.time() - UDPSocket.announceInterval:
self.announceSelf()

View File

@ -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

View File

@ -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()

View File

@ -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