510
512
overrides = dict((k, v) for (k, v) in overrides.iteritems() if k in _valid)
511
513
map.update(overrides)
517
class Reloader(object):
519
This class wraps all paste.reloader logic. All methods are @classmethod.
522
_reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
525
def _turn_sigterm_into_systemexit(self):
527
Attempts to turn a SIGTERM exception into a SystemExit exception.
533
def handle_term(signo, frame):
535
signal.signal(signal.SIGTERM, handle_term)
538
def is_installed(self):
539
return os.environ.get(self._reloader_environ_key)
543
from paste import reloader
544
reloader.install(int(1))
547
def restart_with_reloader(self):
548
"""Based on restart_with_monitor from paste.script.serve."""
549
print 'Starting subprocess with file monitor'
551
args = [sys.executable] + sys.argv
552
new_environ = os.environ.copy()
553
new_environ[self._reloader_environ_key] = 'true'
557
self._turn_sigterm_into_systemexit()
558
proc = subprocess.Popen(args, env=new_environ)
559
exit_code = proc.wait()
561
except KeyboardInterrupt:
562
print '^C caught in monitor process'
566
and hasattr(os, 'kill')):
569
os.kill(proc.pid, signal.SIGTERM)
570
except (OSError, IOError):
573
# Reloader always exits with code 3; but if we are
574
# a monitor, any exit code will restart
577
print '-'*20, 'Restarting', '-'*20