You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The while-True loop in start() blocks any other activities on the controler, such as watching for pressed buttons. With a small modification of your code this would be solved without resorting to multithreading. I implemented it as subclass, but it could easily be integrated:
`import socket
from micropyserver import MicroPyServer
class WebServer(MicroPyServer):
def __init__(self, host="0.0.0.0", port=80, blocking = True):
super().__init__(host, port)
self.blocking = blocking
def start(self):
""" Start server """
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._sock.bind((self._host, self._port))
self._sock.listen(1)
print("Server start")
if self.blocking:
while True:
self.poll()
def poll(self):
if self._sock is not None:
try:
self._connect, address = self._sock.accept()
request = self.get_request()
if len(request) == 0:
self._connect.close()
return
if self._on_request_handler:
if not self._on_request_handler(request, address):
return
route = self.find_route(request)
if route:
route["handler"](self, request)
else:
self._route_not_found(request)
except Exception as e:
self._internal_error(e)
finally:
self._connect.close()
`
The text was updated successfully, but these errors were encountered:
The while-True loop in start() blocks any other activities on the controler, such as watching for pressed buttons. With a small modification of your code this would be solved without resorting to multithreading. I implemented it as subclass, but it could easily be integrated:
`import socket
from micropyserver import MicroPyServer
class WebServer(MicroPyServer):
`
The text was updated successfully, but these errors were encountered: