Worked on the SingleAPI killing issue

This commit is contained in:
jai.s 2020-09-21 20:32:27 +05:30
parent e4ba5a8926
commit 895a3ed16f
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
4 changed files with 19 additions and 6 deletions

View File

@ -90,11 +90,13 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
# pylint:disable=too-few-public-methods # pylint:disable=too-few-public-methods
allow_reuse_address = True allow_reuse_address = True
def serve_forever(self): def forever(self):
"""Start the SimpleXMLRPCServer""" """Start the SimpleXMLRPCServer"""
# pylint: disable=arguments-differ # pylint: disable=arguments-differ
while state.shutdown == 0: while state.shutdown == 0:
self.handle_request() logger.error('before handle_request')
self.serve_forever()
logger.error('After handle_request')
# This thread, of which there is only one, runs the API. # This thread, of which there is only one, runs the API.
@ -106,14 +108,20 @@ class singleAPI(StoppableThread):
def stopThread(self): def stopThread(self):
super(singleAPI, self).stopThread() super(singleAPI, self).stopThread()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
logger.error('11111111111 stopThread 11111111 ')
try: try:
logger.error('11111111111 stopThread 113 ')
s.connect(( s.connect((
BMConfigParser().get('bitmessagesettings', 'apiinterface'), BMConfigParser().get('bitmessagesettings', 'apiinterface'),
BMConfigParser().getint('bitmessagesettings', 'apiport') BMConfigParser().getint('bitmessagesettings', 'apiport')
)) ))
logger.error('11111111111 stopThread 118 ')
s.shutdown(socket.SHUT_RDWR) s.shutdown(socket.SHUT_RDWR)
logger.error('11111111111 stopThread 120 ')
s.close() s.close()
logger.error('11111111111 stopThread 122 ')
except BaseException: except BaseException:
logger.error('11111111111 stopThread except BaseException')
pass pass
def run(self): def run(self):
@ -157,7 +165,7 @@ class singleAPI(StoppableThread):
apiNotifyPath) apiNotifyPath)
BMConfigParser().remove_option( BMConfigParser().remove_option(
'bitmessagesettings', 'apinotifypath') 'bitmessagesettings', 'apinotifypath')
se.serve_forever() se.forever()
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):

View File

@ -129,12 +129,10 @@ class addressGenerator(StoppableThread):
if payloadLengthExtraBytes == 0: if payloadLengthExtraBytes == 0:
payloadLengthExtraBytes = BMConfigParser().getint( payloadLengthExtraBytes = BMConfigParser().getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes')
logger.error('createRandomAddress 176')
if payloadLengthExtraBytes < \ if payloadLengthExtraBytes < \
defaults.networkDefaultPayloadLengthExtraBytes: defaults.networkDefaultPayloadLengthExtraBytes:
payloadLengthExtraBytes = \ payloadLengthExtraBytes = \
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
logger.error('createRandomAddress 181')
if command == 'createRandomAddress': if command == 'createRandomAddress':
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateStatusBar', "" 'updateStatusBar', ""

View File

@ -4,7 +4,7 @@ import logging
import random import random
import threading import threading
from contextlib import contextmanager from contextlib import contextmanager
from pybitmessage.debug import logger
class StoppableThread(threading.Thread): class StoppableThread(threading.Thread):
"""Base class for application threads with stopThread method""" """Base class for application threads with stopThread method"""
@ -22,6 +22,8 @@ class StoppableThread(threading.Thread):
def stopThread(self): def stopThread(self):
"""Stop the thread""" """Stop the thread"""
if self.name == 'singleAPI':
logger.error('yes inside the the stopthread')
self._stopped = True self._stopped = True
self.stop.set() self.stop.set()

View File

@ -35,8 +35,13 @@ def doCleanShutdown():
objectProcessorQueue.put(('checkShutdownVariable', 'no data')) objectProcessorQueue.put(('checkShutdownVariable', 'no data'))
for thread in threading.enumerate(): for thread in threading.enumerate():
# if thread.name == 'singleAPI':
if thread.isAlive() and isinstance(thread, StoppableThread): if thread.isAlive() and isinstance(thread, StoppableThread):
# logger.error('printing the stop thread -{}'.format(
# thread))
thread.stopThread() thread.stopThread()
logger.error('thread name -{} thread._is_stopped {}'.format(
thread.name, thread._is_stopped))
UISignalQueue.put(( UISignalQueue.put((
'updateStatusBar', 'updateStatusBar',