473,748 Members | 4,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

modifying source at runtime - jython case

Hello folks

I want to apply changes in my source code without stopping jython
and JVM. Preferable are modifications directly to instances of
classes. My application is a desktop app using swing library.

Python solutions also interest me.

Solution similiar to "lisp way" is ideal.
Thanks for response,
Jan
Nov 5 '05 #1
7 1783
[Jan Gregor]
I want to apply changes in my source code without stopping jython
and JVM. Preferable are modifications directly to instances of
classes. My application is a desktop app using swing library.

Python solutions also interest me.

Solution similiar to "lisp way" is ideal.


OK, I'll play 20 questions with you.

How close is the following to what you're thinking?

begin SelfMod.java -------------------------------------------
//*************** *************** *************** ***************
import org.python.util .PythonInterpre ter;
import org.python.core .*;

class SelfMod
{

static String my_class_source =
"class MyJyClass:\n" +
" def hello(self):\n" +
" print 'Hello World!'\n";

static String create_instance = "my_instanc e = MyJyClass()\n";

static String invoke_hello = "my_instance.he llo()";

static String overwrite_meth =
"def goodbye():\n"+
" print 'Goodbye world!'\n" +
"\n" +
"my_instance.he llo = goodbye\n";

public static void main ( String args[] )
{
PythonInterpret er interp = new PythonInterpret er();
interp.exec(my_ class_source);
interp.exec(cre ate_instance);
interp.exec(inv oke_hello);
interp.exec(ove rwrite_meth);
interp.exec(inv oke_hello);
}

}
//*************** *************** *************** ***************
end SelfMod.java ---------------------------------------------

need-to-complete-my-coursework-for-telepathy-101-ly y'rs

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
Nov 5 '05 #2
In article <b1************ *****@news.indi go.ie>, Alan Kennedy wrote:
[Jan Gregor]
I want to apply changes in my source code without stopping jython
and JVM. Preferable are modifications directly to instances of
classes. My application is a desktop app using swing library.

Python solutions also interest me.

Solution similiar to "lisp way" is ideal.
OK, I'll play 20 questions with you.

How close is the following to what you're thinking?


I see.

Following try showed me that instances aren't affected by
modification in class definition.
but this helped
x.test = a().test OR x.test = y.test

The only thing left is how to initiate modification, it's a
swing application and i think interp.exec don't stop until
it's done. Maybe somehow call it from jython itself - but need
to pass PythonInterpret er instance.
Thanks.
class a:
def test(self):
print 'first'

x= a()

class a:
def test(self):
print 'second'

y= a()

x.test()
y.test()

begin SelfMod.java -------------------------------------------
//*************** *************** *************** ***************
import org.python.util .PythonInterpre ter;
import org.python.core .*;

class SelfMod
{

static String my_class_source =
"class MyJyClass:\n" +
" def hello(self):\n" +
" print 'Hello World!'\n";

static String create_instance = "my_instanc e = MyJyClass()\n";

static String invoke_hello = "my_instance.he llo()";

static String overwrite_meth =
"def goodbye():\n"+
" print 'Goodbye world!'\n" +
"\n" +
"my_instance.he llo = goodbye\n";

public static void main ( String args[] )
{
PythonInterpret er interp = new PythonInterpret er();
interp.exec(my_ class_source);
interp.exec(cre ate_instance);
interp.exec(inv oke_hello);
interp.exec(ove rwrite_meth);
interp.exec(inv oke_hello);
}

}
//*************** *************** *************** ***************
end SelfMod.java ---------------------------------------------

need-to-complete-my-coursework-for-telepathy-101-ly y'rs

Nov 5 '05 #3
Jan Gregor wrote:
Hello folks

I want to apply changes in my source code without stopping jython
and JVM. Preferable are modifications directly to instances of
classes. My application is a desktop app using swing library.


Can you be more specific? Python and Jython allow classes to be modified at runtime without changing the source code or compiling new code. For example you can add and remove methods and attributes from a class and change the base classes of a class. You can also modify individual instances of a class to change their attributes and behaviour independently of other instances of the class. What are you trying to do? For example see
http://groups.google.com/group/comp....215f7ce8f5d609
http://groups.google.com/group/comp....99041de4b8feb0

Kent
Nov 5 '05 #4
In article <43**********@n ewspeer2.tds.ne t>, Kent Johnson wrote:
Jan Gregor wrote:
Hello folks

I want to apply changes in my source code without stopping jython
and JVM. Preferable are modifications directly to instances of
classes. My application is a desktop app using swing library.


Can you be more specific? Python and Jython allow classes to be modified at runtime without changing the source code or compiling new code. For example you can add and remove methods and attributes from a class and change the base classes of a class. You can also modify individual instances of a class to change their attributes and behaviour independently of other instances of the class. What are you trying to do? For example see
http://groups.google.com/group/comp....215f7ce8f5d609
http://groups.google.com/group/comp....99041de4b8feb0

Kent


thanks for links, I'll look at them.
Alan showed me some possibilities, i'm not quite sure how to initiate
modification and the way import keyword works in case of modified
imported modules.

my typical scenario is that my swing application is running, and i see
some error or chance for improvement - modify sources of app, stop and run
application again.
so task is to reload class defitions (from source files) and modify also
existing instances (their methods).

Jan

Nov 6 '05 #5
Jan Gregor wrote:
my typical scenario is that my swing application is running, and i see
some error or chance for improvement - modify sources of app, stop and run
application again.
so task is to reload class defitions (from source files) and modify also
existing instances (their methods).


Ok, I think my first reply completely missed the mark. IIUC what you want is hard. This recipe might help:
http://aspn.activestate.com/ASPN/Coo.../Recipe/160164

Kent
Nov 6 '05 #6
[Jan Gregor]
Following try showed me that instances aren't affected by
modification in class definition.
Is this more like what you mean?

c:\>jython
Jython 2.1 on java1.4.2_09 (JIT: null)
Type "copyright" , "credits" or "license" for more information.
class a: .... def test(self):
.... print "First"
.... x = a()
x.test() First def test(self): .... print "Second"
.... a.test = test
x.test() Second


If that's what you're thinking, you should read up on class objects,
instance objects and method objects.

http://docs.python.org/tut/node11.ht...00000000000000

[Jan Gregor] my typical scenario is that my swing application is running, and
i see some error or chance for improvement - modify sources of app,
stop and run application again.
You're really talking about an IDE here.
so task is to reload class defitions (from source files) and modify
also existing instances (their methods).


You can modify the behaviour of all existing instances of a class, e.g.
their methods, by modifying the class itself. Any reference to the
method on the instance will resolve to the method definition from its
class, provided you haven't overwritten the method on the individual
instance. Resolving the method is done at invocation time, because
python/jython is a late-binding language.

Any closer?

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
Nov 6 '05 #7
Kent Johnson wrote:
Jan Gregor wrote:
my typical scenario is that my swing application is running, and i see
some error or chance for improvement - modify sources of app, stop and
run
application again.
so task is to reload class defitions (from source files) and modify also
existing instances (their methods).

Ok, I think my first reply completely missed the mark. IIUC what you
want is hard. This recipe might help:
http://aspn.activestate.com/ASPN/Coo.../Recipe/160164

Kent


Yes, this is right way. And it's working.

Thanks,
Jan
Nov 8 '05 #8

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
12617
by: Elbert Lev | last post by:
Hi! Here is the problem: I have a dictionary. Keys are strings. How to make dictionary lookup case insensitive? In other words: If dict = {'First":"Bob", "Last":"Tom"}, dict should return "Bob"
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
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).
13
4531
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only known at run time. Therefore a lot of template based trick isn't too useful. Considering datafile float x(3) 3.5, 2.5, 8.9 double y(3) 2.7, -2.3, 1.2 int z(3) 5, 2, 3
2
1032
by: Jamie Jackson | last post by:
In the XML source I'm working with, some node values that should be identical, vary slightly from value to value. The differences are in whitespace (some have a carriage return mid-string). Ideally, I'd like to normalize-space() all of the values of the underlying data, so that I later use and reuse the cleaned data throughout the rest of the transformation (so I could properly use distinct-values() on that list, etc.). Is there a way...
17
2392
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
0
1786
by: Richard Jones | last post by:
Call for Papers --------------- Open Source Developers' Conference 2007 - Brisbane, Australia "Success in Development & Business" OSDC is a grass-roots conference providing Open Source developers with an opportunity to meet, share, learn, and of course show-off. OSDC focuses on Open Source developers building solutions directly for customers and other end users, anything goes as long as the code or the development
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
8830
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
9544
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, 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...
0
9372
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
9247
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...
1
6796
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
4606
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
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
2215
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.