mirror of
https://github.com/newnius/YAO-agent.git
synced 2025-06-06 21:31:55 +00:00
upgrade to multithreading http service
This commit is contained in:
parent
b5ff2de041
commit
22ee845aad
7
mock.py
7
mock.py
@ -4,6 +4,7 @@ import time
|
|||||||
import json
|
import json
|
||||||
from kafka import KafkaProducer
|
from kafka import KafkaProducer
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
from socketserver import ThreadingMixIn
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
NUMS = os.getenv('NUMS', 1)
|
NUMS = os.getenv('NUMS', 1)
|
||||||
@ -84,6 +85,10 @@ class MyHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_error(404, 'File Not Found: %s' % self.path)
|
self.send_error(404, 'File Not Found: %s' % self.path)
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def report(ClientID):
|
def report(ClientID):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -133,7 +138,7 @@ def listener():
|
|||||||
try:
|
try:
|
||||||
# Create a web server and define the handler to manage the
|
# Create a web server and define the handler to manage the
|
||||||
# incoming request
|
# incoming request
|
||||||
server = HTTPServer(('', PORT), MyHandler)
|
server = ThreadingSimpleServer(('', PORT), MyHandler)
|
||||||
print('Started http server on port ', PORT)
|
print('Started http server on port ', PORT)
|
||||||
|
|
||||||
# Wait forever for incoming http requests
|
# Wait forever for incoming http requests
|
||||||
|
Loading…
Reference in New Issue
Block a user