2017-05-24 16:51:49 +02:00
|
|
|
import threading
|
|
|
|
|
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
from debug import logger
|
|
|
|
from helper_threading import StoppableThread
|
|
|
|
import network.asyncore_pollchoose as asyncore
|
|
|
|
from network.connectionpool import BMConnectionPool
|
|
|
|
|
|
|
|
class BMNetworkThread(threading.Thread, StoppableThread):
|
|
|
|
def __init__(self):
|
2017-05-25 23:04:33 +02:00
|
|
|
threading.Thread.__init__(self, name="AsyncoreThread")
|
2017-05-24 16:51:49 +02:00
|
|
|
self.initStop()
|
|
|
|
self.name = "AsyncoreThread"
|
|
|
|
BMConnectionPool()
|
2017-05-29 00:24:07 +02:00
|
|
|
logger.info("init asyncore thread")
|
2017-05-24 16:51:49 +02:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while not self._stopped:
|
|
|
|
BMConnectionPool().loop()
|
|
|
|
|
|
|
|
def stopThread(self):
|
|
|
|
super(BMNetworkThread, self).stopThread()
|
|
|
|
for i in BMConnectionPool().listeningSockets:
|
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
for i in BMConnectionPool().outboundConnections:
|
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
for i in BMConnectionPool().inboundConnections:
|
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# just in case
|
|
|
|
asyncore.close_all()
|