Worked on the SingleAPI killing issue
This commit is contained in:
parent
e4ba5a8926
commit
895a3ed16f
14
src/api.py
14
src/api.py
|
@ -90,11 +90,13 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
|||
# pylint:disable=too-few-public-methods
|
||||
allow_reuse_address = True
|
||||
|
||||
def serve_forever(self):
|
||||
def forever(self):
|
||||
"""Start the SimpleXMLRPCServer"""
|
||||
# pylint: disable=arguments-differ
|
||||
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.
|
||||
|
@ -106,14 +108,20 @@ class singleAPI(StoppableThread):
|
|||
def stopThread(self):
|
||||
super(singleAPI, self).stopThread()
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
logger.error('11111111111 stopThread 11111111 ')
|
||||
try:
|
||||
logger.error('11111111111 stopThread 113 ')
|
||||
s.connect((
|
||||
BMConfigParser().get('bitmessagesettings', 'apiinterface'),
|
||||
BMConfigParser().getint('bitmessagesettings', 'apiport')
|
||||
))
|
||||
logger.error('11111111111 stopThread 118 ')
|
||||
s.shutdown(socket.SHUT_RDWR)
|
||||
logger.error('11111111111 stopThread 120 ')
|
||||
s.close()
|
||||
logger.error('11111111111 stopThread 122 ')
|
||||
except BaseException:
|
||||
logger.error('11111111111 stopThread except BaseException')
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
|
@ -157,7 +165,7 @@ class singleAPI(StoppableThread):
|
|||
apiNotifyPath)
|
||||
BMConfigParser().remove_option(
|
||||
'bitmessagesettings', 'apinotifypath')
|
||||
se.serve_forever()
|
||||
se.forever()
|
||||
|
||||
|
||||
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||
|
|
|
@ -129,12 +129,10 @@ class addressGenerator(StoppableThread):
|
|||
if payloadLengthExtraBytes == 0:
|
||||
payloadLengthExtraBytes = BMConfigParser().getint(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
logger.error('createRandomAddress 176')
|
||||
if payloadLengthExtraBytes < \
|
||||
defaults.networkDefaultPayloadLengthExtraBytes:
|
||||
payloadLengthExtraBytes = \
|
||||
defaults.networkDefaultPayloadLengthExtraBytes
|
||||
logger.error('createRandomAddress 181')
|
||||
if command == 'createRandomAddress':
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', ""
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
import random
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
|
||||
from pybitmessage.debug import logger
|
||||
|
||||
class StoppableThread(threading.Thread):
|
||||
"""Base class for application threads with stopThread method"""
|
||||
|
@ -22,6 +22,8 @@ class StoppableThread(threading.Thread):
|
|||
|
||||
def stopThread(self):
|
||||
"""Stop the thread"""
|
||||
if self.name == 'singleAPI':
|
||||
logger.error('yes inside the the stopthread')
|
||||
self._stopped = True
|
||||
self.stop.set()
|
||||
|
||||
|
|
|
@ -35,8 +35,13 @@ def doCleanShutdown():
|
|||
|
||||
objectProcessorQueue.put(('checkShutdownVariable', 'no data'))
|
||||
for thread in threading.enumerate():
|
||||
# if thread.name == 'singleAPI':
|
||||
if thread.isAlive() and isinstance(thread, StoppableThread):
|
||||
# logger.error('printing the stop thread -{}'.format(
|
||||
# thread))
|
||||
thread.stopThread()
|
||||
logger.error('thread name -{} thread._is_stopped {}'.format(
|
||||
thread.name, thread._is_stopped))
|
||||
|
||||
UISignalQueue.put((
|
||||
'updateStatusBar',
|
||||
|
|
Reference in New Issue
Block a user