ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Jython-users
Jython-users
Re: [Jython-users] Resetting an embedded interpreter
by Ype Kingma other posts by this author
May 7 2003 2:31AM messages near this date
Re: [Jython-users] java.sql.SQLException: General error | [Jython-users] JOB Python/Java Technical Lead, New York, NY - 80-85k
On Monday 05 May 2003 08:59, Cherney John-CJC030 wrote:
>  I have an interpreter embedded in my java program, and I set the
>  attributes, import the proper modules, and execute the right jython method
>  in the imported script. But I want to reuse that interpreter, setting other
>  attributes, doing other imports, etc. Is there a way I can set it back to
>  some initial state, without having to re-instantiate it? I don't want
>  something I'm executing to have unusual side effects because of something
>  that I imported earlier in the program. Or, worse, have a pool of embedded
>  interpreters where one of them intermittently acts funny because of the
>  combination of scripts it ran over its lifetime. I was looking at the

How much isolation do you want between the interpreted scripts?

>  javadoc for org.python.util.PythonInterpreter and it looks like cleanup or
>  initialize are along the lines of what I want, but cleanup doesn't have any
>  documentation, and initialize can only be called once, and prior to
>  creating a PythonInterpreter. Are there other options?

The cleanup is not documented because it is not part of the python language.

You have full control over the environment in which your scripts run. You can:
- get full isolation between scripts by using a separate class loader and a 
new jython system object for each script.
- combine a thread and an interpreter to run scripts after each other,
  evt. clearing the global namespace between scripts. This lets the
  scripts share the jython system state, mostly the imported modules.
  You can clear the modules loaded into sys.modules between scripts.
  This gets tricky when your scripts change the built in namespace.
- use a new system state for each interpreter.
- let scripts run concurrently on the same global namespace (not recommended).

See http://www.python.org/doc/current/ref/naming.html to determine
what you want to control.

Kind regards,
Ype



-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com

_______________________________________________
Jython-users mailing list
Jython-users@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-users

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved