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,6 +670,7 @@ class ManageCommand():
|
||||||
if not self.process:
|
if not self.process:
|
||||||
return "stopped"
|
return "stopped"
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
code = self.process.poll()
|
code = self.process.poll()
|
||||||
loop = self.maxWaitEnd
|
loop = self.maxWaitEnd
|
||||||
while (code is None) and (loop > 0):
|
while (code is None) and (loop > 0):
|
||||||
|
@ -677,7 +679,10 @@ class ManageCommand():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
code = self.process.poll()
|
code = self.process.poll()
|
||||||
loop -= 1
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
|
try:
|
||||||
loop = self.maxWaitEnd
|
loop = self.maxWaitEnd
|
||||||
while (code is None) and (loop > 0):
|
while (code is None) and (loop > 0):
|
||||||
logging.debug("terminate process %s", self.name)
|
logging.debug("terminate process %s", self.name)
|
||||||
|
@ -685,7 +690,10 @@ class ManageCommand():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
code = self.process.poll()
|
code = self.process.poll()
|
||||||
loop -= 1
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
|
try:
|
||||||
loop = self.maxWaitEnd
|
loop = self.maxWaitEnd
|
||||||
while (code is None) and (loop > 0):
|
while (code is None) and (loop > 0):
|
||||||
logging.debug("kill process %s", self.name)
|
logging.debug("kill process %s", self.name)
|
||||||
|
@ -693,7 +701,10 @@ class ManageCommand():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
code = self.process.poll()
|
code = self.process.poll()
|
||||||
loop -= 1
|
loop -= 1
|
||||||
|
except ProcessLookupError as e:
|
||||||
|
logging.warning("Stop process (%s)" % str(e))
|
||||||
|
|
||||||
|
try:
|
||||||
code = self.process.wait()
|
code = self.process.wait()
|
||||||
self.process = None
|
self.process = None
|
||||||
if self.threadRead:
|
if self.threadRead:
|
||||||
|
@ -701,6 +712,8 @@ class ManageCommand():
|
||||||
self.threadRead.join()
|
self.threadRead.join()
|
||||||
self.threadRead = None
|
self.threadRead = None
|
||||||
logging.info("%s stopped (return code:%d)" % (self.name, code))
|
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