[Twisted-Python] Automatically refresh imported module from source

Thad Jacobs tjacobs at kinematic.com
Fri Feb 28 19:02:19 EST 2003

Hello All,

My name is Thaddeus, and I am new to both Python and Twisted (I found out
about the language and platform yesterday).  I am doing some experimentation
to see how Twisted would benefit our organization.  So far Python blows
every other language I've seen out of the water, in terms of efficiency and
low cost of change.

What I'd like to know is if there is a way to modify the way twisted web
handles requests from within RPY scripts to external py modules.  If I
modify the py module while twisted web is running, I would like to see
subsequent Import requests to that module reference the newly saved version.
I realize that TwistedWeb must be caching the imported modules so future
requests don't require it to re-read from file, but it would seem that it
should at least check the modules modified date to make sure it still has a
current copy whenever the module is requested.

Here's the source for an example that demonstrates my point:

#Begin Test.rpy

from twisted.web import resource
import TestModule

class MyResource(resource.Resource):
	def render(self, request):
		return TestModule.SayHello()

resource = MyResource()

#End Test.rpy

#Begin TestModule.py

def SayHello():
    return "Hello World!!!"

#End Testmodule.py

If I point my browser to test.rpy, "Hello World!!!" is displayed.  This is
great so far.

But when I open up pythonwin, and modify TestModule.py to the following:

#Begin TestModule.py

def SayHello():
    return "Wazzaaap World??!!!"

#End Testmodule.py

And I hit refresh on my browser, "Hello World!!!" still displays.  It is not
until I stop and restart the web server that the change is reflected, and I
am greeted with the revised verbeage.

Must I bring the web server down, every time a make a simple change to an
external module?  There's gotta be a way around this.  The main reason I'm
looking into this platform is to decrease cost of change.

Please let me know,

Thaddeus Jacobs
IT Developer
Kinematic Automation, Inc.
mailto:tjacobs at kinematic.com

More information about the Twisted-Python mailing list