Skip to content

Commit

Permalink
feat: 支持watchdog
Browse files Browse the repository at this point in the history
  • Loading branch information
陈子昂 committed Dec 6, 2023
1 parent faf7947 commit 20678dc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pywss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 20678dc

Please sign in to comment.