class_singleCleaner.py quality fixes

This commit is contained in:
lakshyacis 2019-11-04 20:17:36 +05:30
parent 059e82e2a2
commit 80b2bc1c9a
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB

View File

@ -21,11 +21,11 @@ It resends messages when there has been no response:
import gc import gc
import os import os
import shared
import time import time
import knownnodes import knownnodes
import queues import queues
import shared
import state import state
import tr import tr
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
@ -35,11 +35,12 @@ from network import BMConnectionPool, StoppableThread
class singleCleaner(StoppableThread): class singleCleaner(StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner" name = "singleCleaner"
cycleLength = 300 cycleLength = 300
expireDiscoveredPeers = 300 expireDiscoveredPeers = 300
def run(self): def run(self): # pylint: disable=too-many-branches
gc.disable() gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0 timeWeLastClearedInventoryAndPubkeysTables = 0
try: try:
@ -115,6 +116,7 @@ class singleCleaner(StoppableThread):
# while writing it to disk # while writing it to disk
knownnodes.cleanupKnownNodes() knownnodes.cleanupKnownNodes()
except Exception as err: except Exception as err:
# pylint: disable=protected-access
if "Errno 28" in str(err): if "Errno 28" in str(err):
self.logger.fatal( self.logger.fatal(
'(while writing knownnodes to disk)' '(while writing knownnodes to disk)'
@ -129,15 +131,9 @@ class singleCleaner(StoppableThread):
' is full. Bitmessage will now exit.'), ' is full. Bitmessage will now exit.'),
True) True)
)) ))
# FIXME redundant? if shared.thisapp.daemon or not state.enableGUI:
if shared.daemon or not state.enableGUI:
os._exit(1) os._exit(1)
# # clear download queues
# for thread in threading.enumerate():
# if thread.isAlive() and hasattr(thread, 'downloadQueue'):
# thread.downloadQueue.clear()
# inv/object tracking # inv/object tracking
for connection in BMConnectionPool().connections(): for connection in BMConnectionPool().connections():
connection.clean() connection.clean()
@ -150,7 +146,7 @@ class singleCleaner(StoppableThread):
del state.discoveredPeers[k] del state.discoveredPeers[k]
except KeyError: except KeyError:
pass pass
# TODO: cleanup pending upload / download # ..todo:: cleanup pending upload / download
gc.collect() gc.collect()