cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.45k stars 56 forks source link

Reload socketify #182

Closed leunga1000 closed 4 months ago

leunga1000 commented 4 months ago

Description

This PR fixes https://github.com/cirospaciari/socketify.py/issues/174

Hi, here are some changes for reloading functionality. If --reload is specified the cli.py execute method will poll the files in the run module's directory, excluding some common patterns by default (pycache, node_modules). (os.scandir is used recursively as it caches the modified time information on the files it reads)

If the files have been changed, then

a reload_state flag is set the process will be sent a SIGTERM (for posix and windows compatibility). the sigterm is handled in App.run() to close the loop similar to the SIGINT handler and then a sysexit is raised this sysexit is caught back in cli.py execute In execute(). If the flag has been set (reload_state) then the process will restart, if not, the SIGTERM came from another source and the process will simply stop.

Tested linux, windows.

leunga1000 commented 4 months ago

Added another import signal statement, Python wasn't finding it on another socketify project

leunga1000 commented 4 months ago

Added another import signal statement, Python wasn't finding it on another socketify project

Replaced with os.kill