Skip to content

Commit

Permalink
Asyncore update
Browse files Browse the repository at this point in the history
- shutdown fix
  • Loading branch information
PeterSurda committed May 29, 2017
1 parent bdaa939 commit 0aa5dbd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/network/announcethread.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self):

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()
Expand Down
2 changes: 1 addition & 1 deletion src/network/invthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run(self):
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
Expand Down
5 changes: 3 additions & 2 deletions src/network/networkthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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):
Expand All @@ -15,10 +16,11 @@ def __init__(self):
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()
Expand All @@ -37,4 +39,3 @@ def stopThread(self):

# just in case
asyncore.close_all()
super(BMNetworkThread, self).stopThread()
3 changes: 2 additions & 1 deletion src/network/receivequeuethread.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from network.connectionpool import BMConnectionPool
from network.bmproto import BMProto
import protocol
import state

class ReceiveQueueThread(threading.Thread, StoppableThread):
def __init__(self):
Expand All @@ -21,7 +22,7 @@ def __init__(self):

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
Expand Down

0 comments on commit 0aa5dbd

Please sign in to comment.