Author: chrisz
Date: Mon Feb 21 09:17:44 2011
New Revision: 8153
Log:
Backported file monitoring improvements in AutoReloadingAppServer from 1.1.
Modified:
Webware/branches/Branch-1_0/WebKit/AutoReloadingAppServer.py
Modified: Webware/branches/Branch-1_0/WebKit/AutoReloadingAppServer.py
==============================================================================
--- Webware/branches/Branch-1_0/WebKit/AutoReloadingAppServer.py Mon Feb 21 09:15:58 2011 (r8152)
+++ Webware/branches/Branch-1_0/WebKit/AutoReloadingAppServer.py Mon Feb 21 09:17:44 2011 (r8153)
@@ -36,8 +36,9 @@
python-fam (_fam): http://python-fam.sourceforge.net
"""
+ global fam
+
for module in modules:
- global fam # for Python < 2.2
try:
fam = __import__(module)
except ImportError:
@@ -58,11 +59,14 @@
"""Initialize and start monitoring."""
self._mon = fam.WatchMonitor()
self._watchlist = []
+ self._files = {}
def close(self):
"""Stop monitoring and close."""
- for filepath in self._watchlist:
- self._mon.stop_watch(filepath)
+ watchlist = self._watchlist
+ while watchlist:
+ self._mon.stop_watch(watchlist.pop())
+ self._files = {}
self._mon.disconnect()
def fd(self):
@@ -71,8 +75,10 @@
def monitorFile(self, filepath):
"""Monitor one file."""
- self._mon.watch_file(filepath, self.callback)
- self._watchlist.append(filepath)
+ if filepath not in self._files:
+ self._mon.watch_file(filepath, self.callback)
+ self._watchlist.append(filepath)
+ self._files[filepath] = None
def pending(self):
"""Check whether an event is pending."""
@@ -105,11 +111,14 @@
"""Initialize and start monitoring."""
self._fc = fam.open()
self._requests = []
+ self._files = {}
def close(self):
"""Stop monitoring and close."""
- for request in self._requests:
- request.cancelMonitor()
+ requests = self._requests
+ while requests:
+ requests.pop().cancelMonitor()
+ self._files = {}
self._fc.close()
def fd(self):
@@ -118,7 +127,10 @@
def monitorFile(self, filepath):
"""Monitor one file."""
- self._requests.append(self._fc.monitorFile(filepath, None))
+ if filepath not in self._files:
+ self._requests.append(
+ self._fc.monitorFile(filepath, None))
+ self._files[filepath] = None
def pending(self):
"""Check whether an event is pending."""
|