473,748 Members | 10,771 Online
Bytes | Software Development & Data Engineering Community
+ 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 2188
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=u tf-8&oe=utf-8&q=super_reloa d
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.Syste m.gc() in some test scripts.
Ype

Jul 18 '05 #2
In article <41************ ***********@dre ader19.news.xs4 all.nl>, 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.Syste m.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(my mod)
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************ ***********@dre ader19.news.xs4 all.nl>, 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.Syste m.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(my mod)
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
4560
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 has almost all of it public methods Java synchronized: > > http://cvs.sourceforge.net/viewcvs.py/jython/jython/org/python/core/PyStringMap.
6
2108
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 generous enough to make the two languages possible, that, well, they're kinda different. I guess it was inevitable, but with Jython stuck at Python 2.1, it's not really the same language as CPython is today. You still have to type "from __future__...
4
3427
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
12760
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 and specialed classes for particulars databases. Now there are two options - to include exception (subclasses of SQLException) for every db in except (so all drivers has to be present) or to move methods to subclasses.
1
2296
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 mode as shown below:
12
5922
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 says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
3
2573
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 developer site at Sourceforge. However nothing has been released for over a year (i.e. no support for Python 2.3, 2.4 or 2.5). Is seems that IronPython may have a better future than Jython. I know this is a bit of a troll but I'm concerned about...
4
2044
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 default /root/jython2.2 directory. The install went without issues. However, typing ............jython --version in a teminal still gives me ........ Jython 2.1 on java (JIT: null)
5
3609
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
8989
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, 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...
0
8828
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,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
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 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...
0
8241
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, 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...
1
6795
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4599
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...
1
3309
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 we have to send another system
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.