forked from tornadoweb/tornado
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os, sys, subprocess, threading, time | ||
from apscheduler.schedulers.background import BackgroundScheduler | ||
|
||
from twisted.internet import reactor | ||
|
||
sched = BackgroundScheduler() | ||
sched.start() | ||
|
||
_reload_attempted = False | ||
modify_times = {} | ||
|
||
def start(): | ||
sched.add_job(_reload_on_update, 'interval', seconds=.5, id="poll") | ||
|
||
def _reload_on_update(): | ||
for module, m in sys.modules.items(): | ||
if m is None: | ||
continue | ||
if getattr(m, '__file__', None) is None: | ||
continue | ||
|
||
result = _check_file(m.__file__.lower()) | ||
if result != None: | ||
print("Detected a change in " + str(result) + "\nRestarting " + str(sys.argv[0])) | ||
_reload() | ||
|
||
def _check_file(path): | ||
try: | ||
modified = os.stat(path).st_mtime | ||
except Exception: | ||
return None | ||
|
||
if path not in modify_times: | ||
modify_times[path] = modified | ||
return None | ||
|
||
if modify_times[path] != modified: | ||
return path | ||
|
||
def _reload(): | ||
sched.remove_job("poll") | ||
reactor.callWhenRunning(reactor.stop) | ||
time.sleep(1) | ||
subprocess.Popen([sys.executable] + sys.argv, shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import cyclone.web | ||
import sys | ||
|
||
from twisted.internet import reactor | ||
from twisted.python import log | ||
|
||
|
||
class MainHandler(cyclone.web.RequestHandler): | ||
def get(self): | ||
self.write("Try modifying the server file!") | ||
|
||
if __name__ == "__main__": | ||
application = cyclone.web.Application([ | ||
(r"/", MainHandler) | ||
], autoreload=True) | ||
|
||
log.startLogging(sys.stdout) | ||
reactor.listenTCP(8888, application) | ||
reactor.run() |