Update of /cvsroot/webware/Webware/WebKit
In directory usw-pr-cvs1:/tmp/cvs-serv29753
Modified Files:
AutoReloadingAppServer.py ImportSpy.py
Log Message:
Changed ImportSpy so that it would also add any modules that had been
loaded before it had been set up -- modules like Application fall
into this category.
Also made some minor style changes (""" doc strings and some spaces)
Index: AutoReloadingAppServer.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/AutoReloadingAppServer.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AutoReloadingAppServer.py 24 Oct 2002 22:24:18 -0000 1.1
--- AutoReloadingAppServer.py 25 Oct 2002 06:26:05 -0000 1.2
***************
*** 31,34 ****
--- 31,35 ----
from ImportSpy import modloader
+
DefaultConfig = {
'AutoReload': 0,
***************
*** 99,112 ****
def restartIfNecessary(self):
! """This should be called regularly to see if a restart is required,
! and if so, reinitialize the process using os.execve()
! Tavis Rudd claims: "this method can only be called by the main thread.
! If a worker thread calls it, the process will freeze up."
! I've implemented it so that the ThreadedAppServer's control thread
! calls this. That thread is _not_ the MainThread (the initial thread
! created by the Python interpreter), but I've never encountered any
! problems. Most likely Tavis meant a freeze would occur if a
_worker_ called this.
"""
--- 100,117 ----
def restartIfNecessary(self):
! """
! This should be called regularly to see if a restart is
! required, and if so, reinitialize the process using
! os.execve()
! Tavis Rudd claims: "this method can only be called by
! the main thread. If a worker thread calls it, the
! process will freeze up."
! I've implemented it so that the ThreadedAppServer's
! control thread calls this. That thread is _not_ the
! MainThread (the initial thread created by the Python
! interpreter), but I've never encountered any problems.
! Most likely Tavis meant a freeze would occur if a
_worker_ called this.
"""
***************
*** 128,135 ****
## Callbacks
! def monitorNewModule(self,filepath,mtime):
! """ This is a callback which ImportSpy invokes to notify us
! of new files to monitor. This is only used when we are using FAM."""
! self._requests.append( self._fc.monitorFile(filepath, filepath) )
--- 133,143 ----
## Callbacks
! def monitorNewModule(self, filepath, mtime):
! """
! This is a callback which ImportSpy invokes to notify
! us of new files to monitor. This is only used when we
! are using FAM.
! """
! self._requests.append(self._fc.monitorFile(filepath, filepath) )
***************
*** 144,148 ****
while self._autoReload:
time.sleep(pollInterval)
-
for f, mtime in modloader.fileList().items():
try:
--- 152,155 ----
Index: ImportSpy.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/ImportSpy.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ImportSpy.py 24 Oct 2002 22:24:18 -0000 1.1
--- ImportSpy.py 25 Oct 2002 06:26:05 -0000 1.2
***************
*** 1,6 ****
import ihooks
import os
! ''' ImportSpy.py
The purpose of this module is to record the filepath of every module which
--- 1,8 ----
import ihooks
import os
+ import sys
! """
! ImportSpy.py
The purpose of this module is to record the filepath of every module which
***************
*** 10,15 ****
Other than keeping track of the filepaths, the behaviour of this module
loader is identical to Python's default behaviour.
- '''
class ModuleLoader(ihooks.ModuleLoader):
--- 12,17 ----
Other than keeping track of the filepaths, the behaviour of this module
loader is identical to Python's default behaviour.
+ """
class ModuleLoader(ihooks.ModuleLoader):
***************
*** 19,41 ****
self._fileList = {}
self._notifyHook = None
def load_module(self,name,stuff):
try:
! mod = ihooks.ModuleLoader.load_module(self,name,stuff)
! self.recordFileName(stuff,mod)
except:
! self.recordFileName(stuff,None)
raise
return mod
def fileList(self):
return self._fileList
! def notifyOfNewFiles(self,hook):
! ''' Called by someone else to register that they'd like to
! be know when a new file is imported '''
self._notifyHook = hook
! def addToFileList(self,filepath,getmtime=os.path.getmtime):
modtime = getmtime(filepath)
self._fileList[filepath] = modtime
--- 21,56 ----
self._fileList = {}
self._notifyHook = None
+ self.recordModules(sys.modules.keys())
def load_module(self,name,stuff):
try:
! mod = ihooks.ModuleLoader.load_module(self, name, stuff)
! self.recordFileName(stuff, mod)
except:
! self.recordFileName(stuff, None)
raise
return mod
+ def recordModules(self, moduleNames):
+ for name in moduleNames:
+ mod = sys.modules[name]
+ if not hasattr(mod, '__file__'):
+ # If we can't find it, we can't monitor it
+ continue
+ file = mod.__file__
+ pathname = os.path.dirname(file)
+ desc = None
+ self.recordFileName((file, pathname, desc),
+ sys.modules[name])
+
def fileList(self):
return self._fileList
! def notifyOfNewFiles(self, hook):
! """ Called by someone else to register that they'd like to
! be know when a new file is imported """
self._notifyHook = hook
! def addToFileList(self, filepath, getmtime=os.path.getmtime):
modtime = getmtime(filepath)
self._fileList[filepath] = modtime
***************
*** 44,49 ****
self._notifyHook(filepath,modtime)
! def recordFileName(self,stuff,mod,isfile=os.path.isfile):
! file,pathname,desc = stuff
fileList = self._fileList
--- 59,64 ----
self._notifyHook(filepath,modtime)
! def recordFileName(self, stuff, mod, isfile=os.path.isfile):
! file, pathname, desc = stuff
fileList = self._fileList
***************
*** 72,78 ****
pass
! # also record filepaths which weren't successfully loaded, which
! # may happen due to a syntax error in a servlet, because we also want
! # to know when such a file is modified
elif pathname:
if isfile(pathname):
--- 87,94 ----
pass
! # also record filepaths which weren't successfully
! # loaded, which may happen due to a syntax error in a
! # servlet, because we also want to know when such a
! # file is modified
elif pathname:
if isfile(pathname):
***************
*** 87,94 ****
ihooks.install(imp)
! ''' These two methods are compatible with the 'imp' module (and can
therefore be useds as drop-in replacements), but will use the
above ModuleLoader to record the pathnames of imported modules.
! '''
def load_module(name, file, filename, description):
--- 103,110 ----
ihooks.install(imp)
! """ These two methods are compatible with the 'imp' module (and can
therefore be useds as drop-in replacements), but will use the
above ModuleLoader to record the pathnames of imported modules.
! """
def load_module(name, file, filename, description):
|