|
From: Adrian S. J. <as...@pa...> - 2001-06-26 12:32:56
|
(Reply to Ype, with clarification)
-----Original Message-----
From: Adrian St. John [mailto:as...@pa...]
Sent: 26 June 2001 13:03
To: Ype Kingma
Subject: RE: [Jython-users] Multiple instances of embedded
JythonInterpreter
> From: Ype Kingma [mailto:yk...@xs...]
>
> >stdout/stderr for all instances get redirected to the last one set.
>
> Stdout/stderr are 'one per process'. You'll have to use your own
> output functions (or methods) in your threads. You can use
> the thread identity provided by Jython to select a network
> connection in your output functions.
I already do a fair amount of this; I think I assumed that I could
set the Jython stdout/stderr (not the Java one) on a per-instance basis.
I'll go back and look at my code.
> >If I try to 'set' a variable in one interpreter from another, the
> >variable gets lost.
>
> Variables in module scope are 'one per process', because modules
> are 'one per process'. If you change these, the changes are visible
> in other threads. You'll probably need the threading module
> to synchronize access to these.
> Local function variables are 'one per thread', and invisible to
> other threads.
Just to explain exactly what I'm doing:
(Java code, from memory):
public class Player
{
private InteractiveInterpreter _interp;
public Player()
{
_interp = new InteractiveInterpreter();
_interp.set("me", this);
}
};
If an instance of Player is created from pure Java code (ie not inside
a Jython interpreter instance), the variable 'me' exists in the interpreter.
If an instance of Player is created from inside a Jython interpreter
instance,
the variable 'me' doesn't exist.
CLARIFICATION:
What I should have said is:
If an instance of Player is created from pure Java code (ie not inside
a Jython interpreter instance), the variable 'me' exists in the
Player._interp
(ie Player._interp.exec("print me") results in a name-not-known exception)
If an instance of Player is created from inside a Jython interpreter
instance,
the variable 'me' doesn't exist in Player._interp
Any ideas?
Thanks,
Adrian.
|