473,404 Members | 2,187 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,404 software developers and data experts.

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 1762
[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.PythonInterpreter;
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_instance = MyJyClass()\n";

static String invoke_hello = "my_instance.hello()";

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

public static void main ( String args[] )
{
PythonInterpreter interp = new PythonInterpreter();
interp.exec(my_class_source);
interp.exec(create_instance);
interp.exec(invoke_hello);
interp.exec(overwrite_meth);
interp.exec(invoke_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.indigo.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 PythonInterpreter 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.PythonInterpreter;
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_instance = MyJyClass()\n";

static String invoke_hello = "my_instance.hello()";

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

public static void main ( String args[] )
{
PythonInterpreter interp = new PythonInterpreter();
interp.exec(my_class_source);
interp.exec(create_instance);
interp.exec(invoke_hello);
interp.exec(overwrite_meth);
interp.exec(invoke_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**********@newspeer2.tds.net>, 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
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: 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...
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
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...
13
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...
2
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). ...
17
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
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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.