473,323 Members | 1,560 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,323 software developers and data experts.

jython question (interesting behavior)

Is this the correct place to post a jython question?

I posted the following in the jython group, but I figured I'd post here
too:
_________________________________________
I am assuming that the PythonInterpreter environment is not a unique
environment from within a jvm.

Here is some pseudo code to show what I am talking about
1) create a jython module file, lets call it "mytest"
with a simple static class
class simpleS:
myVar = "test01"
2) Now set up two interpreter environments from within
the same jvm
PythonInterpreter py = new PythonInterpreter()
PythonInterpreter py1 = new PythonInterpreter()
3) now in both interpreters, import the module
py.exec("import mytest")
py1.exec("import mytest")
Now for both interpreters run
"print mytest.simpleS.myVar"
4) Now for the crazy part.
in the py interpreter run
"mytest.simpleS.myVar = 'test02'
in py1 look at the value
"print mytest.simpleS.myVar"

Very interesting behavior. So it seems that each python interpreter
instance does not act as its own seperate space.

Maybe I just have not gotten there yet with the docs. I did notice
something about the initialize() function associated with the
interpreter which is only supposed to be run once.

Jul 18 '05 #1
2 1534
Hmm, now that I think about this, maybe it's not so crazy.

It would be the equivalent of modifying a static variable in the same
JVM. Sorry to bother.

Jul 18 '05 #2
pythonUser_07 wrote:
Is this the correct place to post a jython question?

I posted the following in the jython group, but I figured I'd post here
too:
_________________________________________
I am assuming that the PythonInterpreter environment is not a unique
environment from within a jvm.

Here is some pseudo code to show what I am talking about
1) create a jython module file, lets call it "mytest"
with a simple static class
class simpleS:
myVar = "test01"
2) Now set up two interpreter environments from within
the same jvm
PythonInterpreter py = new PythonInterpreter()
PythonInterpreter py1 = new PythonInterpreter()
3) now in both interpreters, import the module
py.exec("import mytest")
py1.exec("import mytest")
Now for both interpreters run
"print mytest.simpleS.myVar"
4) Now for the crazy part.
in the py interpreter run
"mytest.simpleS.myVar = 'test02'
in py1 look at the value
"print mytest.simpleS.myVar"

Very interesting behavior. So it seems that each python interpreter
instance does not act as its own seperate space.


My understanding is that the two PythonInterpreters wrap a single PySystemState which is where the
modules are cached. So they share the same modules. If you want different behaviour you should give
them each their own PySystemState.

Kent
Jul 18 '05 #3

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
11
by: Maurice LING | last post by:
Hi, I'm looking for a suitable thesis topic, so I hope that I can gather some advice on this area that I'm thinking of. Jython appears as a relatively successful attempt to bridge Python to...
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...
4
by: Nadeem Mohsin | last post by:
Me and a couple of friends have been thinking of doing something involving Python for our final year undergrad project. We're considering the first idea mentioned on this page:...
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.