from PySide6.QtCore import QThread, Slot
from src.utils.documentation import website, QuietHandler
from wsgiref.simple_server import make_server


class DocumentationThread(QThread):
    def __init__(self):
        super().__init__()
        self._server = None  # store server so we can shut it down

    def run(self):
        # launch_documentation()
        self._server = make_server(
            "localhost", 8000, website(), handler_class=QuietHandler
        )
        while not self.isInterruptionRequested():
            self._server.handle_request()

    @Slot()  # slot you can connect to aboutToQuit
    def stop(self):
        self.requestInterruption()  # ask the loop above to exit
        if self._server:
            self._server.shutdown()  # unblock handle_request()