473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

reloading updated modules in long running server?

I am looking for a way for reloading updated modules in a long running
server. I'm not too concerned about cascaded reload or objects already
created. Just need to reload module xxx if the corresponding xxx.py is
updated.

I found something useful in module.__file__. Would it work if I use it to
generate filenames xxx.py xxx.pyc and then compare their mtime? I'm not
too sure about the mechanism of generation of .pyc file. Would it be too
system specific to reply on?
Jul 18 '05 #1
2 1639
I don't know if there is a way to catch the event "a file has been
modified in the file system" but you can always check if something has
changed in sys.modules every time a request is processed by the server,
or every n second

Something like this should work :

updateTime={}
for m in sys.modules.values():
if m and hasattr(m,"__file__"):
modTime=os.path.getmtime(m.__file__)
if updateTime.has_key(m):
if modTime != updateTime[m]:
reload(m)
updateTime[m]=modTime
else:
updateTime[m]=modTime

Pierre

aurora a écrit :
I am looking for a way for reloading updated modules in a long running
server. I'm not too concerned about cascaded reload or objects already
created. Just need to reload module xxx if the corresponding xxx.py is
updated.

I found something useful in module.__file__. Would it work if I use it
to generate filenames xxx.py xxx.pyc and then compare their mtime? I'm
not too sure about the mechanism of generation of .pyc file. Would it
be too system specific to reply on?

Jul 18 '05 #2
Pierre Quentel wrote:
I don't know if there is a way to catch the event "a file has been
modified in the file system" but you can always check if something has
changed in sys.modules every time a request is processed by the server,
or every n second

Something like this should work :

updateTime={}
for m in sys.modules.values():
if m and hasattr(m,"__file__"):
modTime=os.path.getmtime(m.__file__)
if updateTime.has_key(m):
if modTime != updateTime[m]:
reload(m)
updateTime[m]=modTime
else:
updateTime[m]=modTime

Pierre


if you have class A in module a.py and class B(A) in module b.py, and in module c.py you instantiale b = B(). will
there be a problem if you reload module b, then c, then a? in the previous example, m in sys.modules.values() doesn't
take this into account.

bryan
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy Jewell | last post by:
Does anyone know of a way to dynamically reload all the imported modules of a client module? I'm writing a program that I have broken down into quite a few submodules, and the 'configuration'...
0
by: OKB (not okblacke) | last post by:
I'm fooling around with some MUD server code, and I want to add a "reload" command that will let MUD wizards reload the server modules, so that changes to the MUD parser and such can be effected...
0
by: Joseph Krauze | last post by:
Assume a main python file that does the following: from lib_mod import performAction def main(): return performAction("myFile") Now, if I modify lib_mod.py and just try to reload main.py,...
2
by: Lowell Kirsh | last post by:
I have a driver module as well as several other modules. I am running the driver interactively from emacs - that is, I don't restart python on each run. I want to work it such that every time a...
2
by: Snolly | last post by:
Hi all, Here is my issue. I have a web page (lets call it page1) with an iframe in it that then opens a pop-up window (page2). The pop-up window is used to edit some data that was loaded into...
7
by: John Murtari | last post by:
Folks, We would like to upgrade our servers to PHP 5 and PHP 4 together as modules on the same server (not as cgi, not passing requests to another server). I did some extensive searching on...
7
by: John Nagle | last post by:
I'm converting a web app from CGI to FCGI. The application works fine under FCGI, but it's being reloaded for every request, which makes FCGI kind of pointless. I wrote a little FCGI app which...
1
by: lukasz.f24 | last post by:
Hello, I came across annoying problem during my fun with mod_python. I turned out that mod_python load package only onca and don't care about any changes to it. Obviously it makes sense on...
7
by: Tlis | last post by:
I am using a software system with an embedded Python interpreter (version 2.3) for scripting. The KcsPoint2D.py module contains a Point2D class with the following method: def...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.