Make sure bot.lock is released in do_GET

This commit is contained in:
jesopo 2018-10-04 17:18:24 +01:00
parent fdddb33f32
commit 7fc0359e3d

View file

@ -8,6 +8,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
timeout = 10 timeout = 10
def do_GET(self): def do_GET(self):
_bot.lock.acquire() _bot.lock.acquire()
try:
parsed = urllib.parse.urlparse(self.path) parsed = urllib.parse.urlparse(self.path)
query = parsed.query query = parsed.query
get_params = urllib.parse.parse_qs(query) get_params = urllib.parse.parse_qs(query)
@ -25,16 +26,17 @@ class Handler(http.server.BaseHTTPRequestHandler):
params=get_params, path=endpoint.split("/")) params=get_params, path=endpoint.split("/"))
if response: if response:
response = json.dumps(response, sort_keys=True, indent=4) response = json.dumps(response, sort_keys=True,
indent=4)
code = 200 code = 200
self.send_response(code) self.send_response(code)
self.send_header("Content-type", "application/json") self.send_header("Content-type", "application/json")
self.end_headers() self.end_headers()
try:
self.wfile.write(response.encode("utf8")) self.wfile.write(response.encode("utf8"))
except: except:
pass pass
finally:
_bot.lock.release() _bot.lock.release()
@utils.export("botset", {"setting": "rest-api", @utils.export("botset", {"setting": "rest-api",