Asyncore update
- shutdown fix
This commit is contained in:
parent
bdaa939e2c
commit
0aa5dbd958
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue
Block a user