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? 2 1662
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.val ues():
if m and hasattr(m,"__fi le__"):
modTime=os.path .getmtime(m.__f ile__)
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?
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.val ues(): if m and hasattr(m,"__fi le__"): modTime=os.path .getmtime(m.__f ile__) 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.val ues() doesn't
take this into account.
bryan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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' is done with modules too. As I am developing the app, I
need to test bits and pieces here and there. This is what I currently do:
In each module, I have a section, just after the main imports like so:
|
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 without
having to shut down and restart the server.
Now, what I want to do at the top of my main module, instead of
just "import somemodule", is something like this:
try:
reload(somemodule)
|
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, lib_mod is not
updated. I have searched online and came upon a few tinkers but nothing
that seemed to be blessed by python.org. Is there a feature or an
official modification that I'm missing?
|
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 modify the source for
one of the non-driver modules and re-run the driver, the other modules
will be reloaded. I have the following at the top of my driver module:
import dbtest, util
for module in :
if module in sys.modules.keys():...
|
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 page1 so I want
to use onunload to reload page1 to keep the data synchronized.
At first I was using just
window.opener.parent.location = window.opener.parent.location;
| |
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
this and we ran some tests over a year ago and did not find a
solution (other than proxy forwarding to a PHP 5 configured server).
When PHP went to version 4 from version 3, it was possible
to run both at the same time, and have users select by...
|
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 prints when the program is
loaded and when it gets a request. And indeed, the program gets reloaded for
each HTTP request. Something is probably misconfigured. But what?
I'm using Apache with "mod_fcgid", configured via Plesk. Plesk
sets up...
|
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 production server but
during development is more then annoying. I find a way to reload my
module:
m = apache.import_module(name)
reload(m)
|
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 SetFromMidpoint(self, p1, p2):
if not isinstance(p1, Point2D) or not isinstance(p2, Point2D):
raise TypeError, 'some error message'
---
The problem is that after I launch my script once, and then use the
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |