summaryrefslogtreecommitdiff
path: root/paste/reloader.py
diff options
context:
space:
mode:
authorcce <devnull@localhost>2006-01-11 08:11:04 +0000
committercce <devnull@localhost>2006-01-11 08:11:04 +0000
commit3549c4ddf33a42981cdf74314ca38ac182f15800 (patch)
tree02ec9583cf006e654a5ca8330bea1ef9b1e104a1 /paste/reloader.py
parent408ce1d2e6ddeb9ba1c97e9ae8e2e2259d56fb0c (diff)
downloadpaste-3549c4ddf33a42981cdf74314ca38ac182f15800.tar.gz
- updated httpserver to have better documentation for serve()
- added socket_timeout option - added deamon_threads option - the port option to serve() can now be a string - now catching and re-routing most socket errors (which are routine) - converted reload.py to use a deamon thread - added comment why os._exit is used - removed raise_keyboard_interrupt option (this might need to be re-added later, just not sure what it does)
Diffstat (limited to 'paste/reloader.py')
-rw-r--r--paste/reloader.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/paste/reloader.py b/paste/reloader.py
index 6144b60..be14156 100644
--- a/paste/reloader.py
+++ b/paste/reloader.py
@@ -23,45 +23,42 @@ import os
import sys
import time
import threading
-import atexit
from paste.util.classinstance import classinstancemethod
-def install(poll_interval=1, raise_keyboard_interrupt=True):
+def install(poll_interval=1):
"""
Install the reloading monitor.
+
+ On some platforms server threads may not terminate when the main
+ thread does, causing ports to remain open/locked. The
+ ``raise_keyboard_interrupt`` option creates a unignorable signal
+ which causes the whole application to shut-down (rudely).
"""
- mon = Monitor(poll_interval=poll_interval,
- raise_keyboard_interrupt=raise_keyboard_interrupt)
+ mon = Monitor(poll_interval=poll_interval)
t = threading.Thread(target=mon.periodic_reload)
+ t.setDaemon(True)
t.start()
-
+
class Monitor:
instances = []
global_extra_files = []
- def __init__(self, poll_interval, raise_keyboard_interrupt):
+ def __init__(self, poll_interval):
self.module_mtimes = {}
- atexit.register(self.atexit)
self.keep_running = True
self.poll_interval = poll_interval
- self.raise_keyboard_interrupt = raise_keyboard_interrupt
self.extra_files = self.global_extra_files[:]
self.instances.append(self)
- def atexit(self):
- self.keep_running = False
- if self.raise_keyboard_interrupt:
- # This exception is somehow magic, because it applies
- # to more threads and situations (like socket.accept)
- # that a mere SystemExit will not.
- raise KeyboardInterrupt("Exiting process")
-
def periodic_reload(self):
while 1:
- if not self.keep_running:
- break
if not self.check_reload():
+ # use os._exit() here and not sys.exit() since within a
+ # thread sys.exit() just closes the given thread and
+ # won't kill the process; note os._exit does not call
+ # any atexit callbacks, nor does it do finally blocks,
+ # flush open files, etc. In otherwords, it is rude.
os._exit(3)
break
time.sleep(self.poll_interval)