473,473 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Jython and super_reload?

There have been several discussions here about how to write a reload()
function that works for classes as well as modules:

http://groups.google.com/groups?sour...q=super_reload

I have been trying to come up with a solution that works for Jython, and so
far nothing has worked. I was wondering if anyone has attempted or succeeded
in writing such a function for Jython.

Thanks,
Dave

--
.:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
Jul 18 '05 #1
3 2176
Dave Benjamin wrote:
There have been several discussions here about how to write a reload()
function that works for classes as well as modules:

http://groups.google.com groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=super_reload
I have been trying to come up with a solution that works for Jython, and so far nothing has worked. I was wondering if anyone has attempted or succeeded in writing such a function for Jython.


This works for classes:

http://www.jython.org/docs/jreload.html

You can unload a module in Jython by removing it from sys.modules,
and (off course) by removing all other references to it.

To be sure about what happens you can tell the JVM to be verbose
about garbage collection of Java classes, and explicitly call
java.lang.System.gc() in some test scripts.
Ype

Jul 18 '05 #2
In article <41***********************@dreader19.news.xs4all.n l>, Ype Kingma wrote:

This works for classes:

http://www.jython.org/docs/jreload.html

You can unload a module in Jython by removing it from sys.modules,
and (off course) by removing all other references to it.

To be sure about what happens you can tell the JVM to be verbose
about garbage collection of Java classes, and explicitly call
java.lang.System.gc() in some test scripts.


Thanks for the link and the comments, but I don't think this is quite what
I'm trying to do here. I'm not trying to reload Java classes, I'm trying to
reload Python modules such that any instances of the old version of that
module's classes get updated to use the new methods. For instance:

mymod.py
--------
class A:
def test(self):
print 'hello'

app
---
import mymod
a = A()
a.test()
(output: 'hello')

mymod.py
--------
class A:
def test(self):
print 'goodbye'

app
---
reload(mymod)
a.test()
(output: still 'hello')

# This is what I've been unable to accomplish:
from magic import super_reload
super_reload(mymod)
a.test()
(output: 'goodbye')

Does that make sense? The end result is that I want to be able to modify
classes in a running application and have this affect all existing class
instances. This is important because I am working in an application server
environment where restarts are costly and time-consuming, and instances are
often kept in user sessions. Currently, any changes to a class require that
the session be reinitialized (ie. you have to log out and log back in),
which makes incremental testing and development awkward.

Thanks!
Dave

--
.:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
"talking about music is like dancing about architecture."
Jul 18 '05 #3
Dave Benjamin wrote:
In article <41***********************@dreader19.news.xs4all.n l>, Ype Kingma wrote:

This works for classes:

http://www.jython.org/docs/jreload.html

You can unload a module in Jython by removing it from sys.modules,
and (off course) by removing all other references to it.

To be sure about what happens you can tell the JVM to be verbose
about garbage collection of Java classes, and explicitly call
java.lang.System.gc() in some test scripts.


Thanks for the link and the comments, but I don't think this is quite what
I'm trying to do here. I'm not trying to reload Java classes, I'm trying

to reload Python modules such that any instances of the old version of that
module's classes get updated to use the new methods. For instance:

mymod.py
--------
class A:
def test(self):
print 'hello'

app
---
import mymod
a = A()
a.test()
(output: 'hello')

mymod.py
--------
class A:
def test(self):
print 'goodbye'

app
---
reload(mymod)
a.test()
(output: still 'hello')

# This is what I've been unable to accomplish:
from magic import super_reload
super_reload(mymod)
a.test()
(output: 'goodbye')

Does that make sense? The end result is that I want to be able to modify
classes in a running application and have this affect all existing class
instances. This is important because I am working in an application server
I don't think the Python language supports it.
One could replace the module in sys.modules, but that does not remove the
reference to the old module and its contents in existing instances.
environment where restarts are costly and time-consuming, and instances are often kept in user sessions. Currently, any changes to a class require that the session be reinitialized (ie. you have to log out and log back in),
which makes incremental testing and development awkward.


You might solve the problem by convincing the users to reinstantiate their
classes after replacing the module in sys.modules.

Replacing the Python class of a Python instance is tricky (to say the least)
because of Python's dynamic nature. And even without Python dynamics one
can get into strange situations.

When you convince the users to reinstantiate their classes,
my guess is that sooner rather than later some of your users will manage
to bring their sessions into an irreproducable (error) state because they
forgot to replace some instances.

In a Java JVM one can have multiple fully independent Jython
system states by using different Java class loaders. This is safe, but it
costs some memory. This has been done by others, please check the
jython-user and jython-dev archives.

Good luck,
Ype

Jul 18 '05 #4

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

Similar topics

4
by: Michael Chermside | last post by:
Ype writes: > For the namespaces in Jython this 'Python internal thread safety' > is handled by the Java class: > > http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html > > which...
6
by: Dave Benjamin | last post by:
Hey good people, I've been doing a lot of simultaneous Jython and CPython programming lately, and just wanted to say, with no intended ill will toward any of the individuals who have been...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
7
by: Jan Gregor | last post by:
Hello I found that jython catches exact java exceptions, not their subclasses. Is there some way to get around this limitation (or error) ? My program has class representing database source...
1
by: scott | last post by:
I installed darwinports and did a "sudo port install jython" ------------------------- scott$ which jython /opt/local/bin/jython ------------------------- Jython works in interactive...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
3
by: Sloan.Kohler | last post by:
Is Jython development dead or has it just seemed that way for over a year?. The jython.org website has a recent new appearance (but no new content) and there is some message traffic on the...
4
by: Neil Wallace | last post by:
Hi all, I am a novice Python/Jython programmer, and Ubuntu user. Ubuntu still only supports only version 2.1 of Jython. I have used the GUI installer of Jython 2.2, and installed it to the...
5
by: sarup26 | last post by:
Hello .. I would like to know more about Python and Jython? What is the difference between both of them? What is the future for Jython and which are the areas where it is used? Swot
0
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...
1
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
tracyyun
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...
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.