From 20678dca4f504bfcb3a19d975ea9e96f8f420689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E6=98=82?= Date: Wed, 6 Dec 2023 13:43:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81watchdog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywss/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pywss/__init__.py b/pywss/__init__.py index 83752b0..0861db3 100644 --- a/pywss/__init__.py +++ b/pywss/__init__.py @@ -339,6 +339,15 @@ def __flush_body(self): chunk = body.read(8192) body.close() + def __str__(self): + firstline = f"{self.method} {self.route} {self.version}" + header = '\r\n'.join([f"{k}: {v}" for k, v in self.headers.items()]) + body = self.body().decode() + return f"{firstline}\r\n{header}\r\n\r\n{body}" + + def __bytes__(self): + return self.body() + class App: @@ -706,6 +715,8 @@ def watchdog(self, interval: float = float(os.environ.get("PYWSS_WATCHDOG_INTERV key = f"{route}" handler = handlers[-1] module = inspect.getmodule(handler) + if module.__name__ == "__main__": # only restart + continue sourcefile = inspect.getsourcefile(module) mtime = int(os.path.getmtime(sourcefile)) if key not in stat: