2018-10-03 17:42:12 +02:00
|
|
|
import network.asyncore_pollchoose as asyncore
|
|
|
|
import state
|
2017-05-24 16:51:49 +02:00
|
|
|
from network.connectionpool import BMConnectionPool
|
2018-10-03 17:42:12 +02:00
|
|
|
from queues import excQueue
|
2019-08-06 13:04:33 +02:00
|
|
|
from threads import StoppableThread
|
2018-10-03 17:42:12 +02:00
|
|
|
|
2017-05-24 16:51:49 +02:00
|
|
|
|
2019-08-01 13:37:26 +02:00
|
|
|
class BMNetworkThread(StoppableThread):
|
2019-09-12 13:50:08 +02:00
|
|
|
"""A thread to handle network concerns"""
|
2019-08-06 13:04:33 +02:00
|
|
|
name = "Asyncore"
|
2017-05-24 16:51:49 +02:00
|
|
|
|
|
|
|
def run(self):
|
2018-10-03 17:42:12 +02:00
|
|
|
try:
|
|
|
|
while not self._stopped and state.shutdown == 0:
|
|
|
|
BMConnectionPool().loop()
|
|
|
|
except Exception as e:
|
|
|
|
excQueue.put((self.name, e))
|
|
|
|
raise
|
2017-05-24 16:51:49 +02:00
|
|
|
|
|
|
|
def stopThread(self):
|
2017-05-29 14:35:08 +02:00
|
|
|
super(BMNetworkThread, self).stopThread()
|
2018-01-31 21:09:36 +01:00
|
|
|
for i in BMConnectionPool().listeningSockets.values():
|
2017-05-24 16:51:49 +02:00
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
2018-01-31 21:09:36 +01:00
|
|
|
for i in BMConnectionPool().outboundConnections.values():
|
2017-05-24 16:51:49 +02:00
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
2018-01-31 21:09:36 +01:00
|
|
|
for i in BMConnectionPool().inboundConnections.values():
|
2017-05-24 16:51:49 +02:00
|
|
|
try:
|
|
|
|
i.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# just in case
|
|
|
|
asyncore.close_all()
|