Better way to stop server

This commit is contained in:
Samuel Sloniker 2024-07-29 09:42:37 -07:00
parent 3d5aa298c9
commit 6d4855ff58

View File

@ -1,10 +1,19 @@
import multiprocessing
import webbrowser
import threading
import asyncio
import signal
import time
import sys
import os
import markdown
import tornado.ioloop
import tornado.web
import navpoint.fix_path
def timed_exit():
time.sleep(3)
os.kill(os.getpid(), signal.SIGTERM)
class AboutHandler(tornado.web.RequestHandler):
def get(self):
@ -44,19 +53,22 @@ class AboutHandler(tornado.web.RequestHandler):
</html>
"""
)
tornado.ioloop.IOLoop.instance().stop()
threading.Thread(target=timed_exit).start()
def _run():
async def _run():
app = tornado.web.Application(
[
("/", AboutHandler),
]
)
app.listen(9999, address="127.0.0.1")
tornado.ioloop.IOLoop.instance().start()
await asyncio.Event().wait()
def _wrapper():
asyncio.run(_run())
def about():
threading.Thread(target=_run).start()
multiprocessing.Process(target=_wrapper).start()
webbrowser.open("http://127.0.0.1:9999/")