adding multithread for http server, and manage some error
This commit is contained in:
parent
3b901be756
commit
69cd23bf84
2 changed files with 43 additions and 30 deletions
|
@ -142,6 +142,7 @@ import json
|
||||||
import fcntl
|
import fcntl
|
||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
|
from socketserver import ThreadingMixIn
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
@ -455,7 +456,7 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
|
|
||||||
class khaganatHTTPServer(http.server.HTTPServer):
|
class khaganatHTTPServer(ThreadingMixIn, http.server.HTTPServer):
|
||||||
"""
|
"""
|
||||||
Class khaganatHTTPServer
|
Class khaganatHTTPServer
|
||||||
Redefine HTTPServer (adding queue input & queue output, use by ManageHttpRequest)
|
Redefine HTTPServer (adding queue input & queue output, use by ManageHttpRequest)
|
||||||
|
@ -669,38 +670,50 @@ class ManageCommand():
|
||||||
if not self.process:
|
if not self.process:
|
||||||
return "stopped"
|
return "stopped"
|
||||||
else:
|
else:
|
||||||
code = self.process.poll()
|
try:
|
||||||
loop = self.maxWaitEnd
|
|
||||||
while (code is None) and (loop > 0):
|
|
||||||
logging.debug("stop process %s", self.name)
|
|
||||||
self.process.send_signal(15)
|
|
||||||
time.sleep(1)
|
|
||||||
code = self.process.poll()
|
code = self.process.poll()
|
||||||
loop -= 1
|
loop = self.maxWaitEnd
|
||||||
|
while (code is None) and (loop > 0):
|
||||||
|
logging.debug("stop process %s", self.name)
|
||||||
|
self.process.send_signal(15)
|
||||||
|
time.sleep(1)
|
||||||
|
code = self.process.poll()
|
||||||
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
loop = self.maxWaitEnd
|
try:
|
||||||
while (code is None) and (loop > 0):
|
loop = self.maxWaitEnd
|
||||||
logging.debug("terminate process %s", self.name)
|
while (code is None) and (loop > 0):
|
||||||
self.process.terminate()
|
logging.debug("terminate process %s", self.name)
|
||||||
time.sleep(1)
|
self.process.terminate()
|
||||||
code = self.process.poll()
|
time.sleep(1)
|
||||||
loop -= 1
|
code = self.process.poll()
|
||||||
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
loop = self.maxWaitEnd
|
try:
|
||||||
while (code is None) and (loop > 0):
|
loop = self.maxWaitEnd
|
||||||
logging.debug("kill process %s", self.name)
|
while (code is None) and (loop > 0):
|
||||||
self.process.send_signal(9)
|
logging.debug("kill process %s", self.name)
|
||||||
time.sleep(1)
|
self.process.send_signal(9)
|
||||||
code = self.process.poll()
|
time.sleep(1)
|
||||||
loop -= 1
|
code = self.process.poll()
|
||||||
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
code = self.process.wait()
|
try:
|
||||||
self.process = None
|
code = self.process.wait()
|
||||||
if self.threadRead:
|
self.process = None
|
||||||
self.eventRunning.clear()
|
if self.threadRead:
|
||||||
self.threadRead.join()
|
self.eventRunning.clear()
|
||||||
self.threadRead = None
|
self.threadRead.join()
|
||||||
logging.info("%s stopped (return code:%d)" % (self.name, code))
|
self.threadRead = None
|
||||||
|
logging.info("%s stopped (return code:%d)" % (self.name, code))
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
return "stopped"
|
return "stopped"
|
||||||
|
|
||||||
def getlog(self, firstline):
|
def getlog(self, firstline):
|
||||||
|
|
|
@ -339,7 +339,7 @@ class TestManager(unittest.TestCase):
|
||||||
self.assertEqual(res, 'stopped')
|
self.assertEqual(res, 'stopped')
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Error when run test', e)
|
self.fail('Error when run test (%s)' % str(e))
|
||||||
|
|
||||||
def test_execute_command_crashed(self):
|
def test_execute_command_crashed(self):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue