That is great - exactly what I was looking for!

w.r.t. modjy - I may switch over to using it; when i started my project it wasn't clear to me that modjy could meet all my requirements (I had specific concerns around module reloading) but after looking through the source I think it will.

Thanks for your help,


Date: Thu, 1 Jul 2010 20:20:23 +0100
From: Alan Kennedy <>
Subject: Re: [Jython-dev] Is jython thread safe?
Content-Type: text/plain; charset=ISO-8859-1

> Can anyone tell me if the PythonInterpreter is thread safe?

PythonInterpreter is thread-safe.

> That is, can two
> thread simultaneously call into the interpreter and evaluate different
> scripts? Are there any operations that are not thread safe and need to be
> synchronized by the caller?

But the exec and execfile methods of PythonInterpreter are not
thread-safe, so you need to synchronize them when

> I have been searching all through the jython docs and googling like mad, but
> I can't seem to find an authoritative answer to this question. Maybe if
> someone on this mailing list knows, he or she can create a short article in
> the Jython wiki addressing this question.

That's a good idea. Probably a link to the relevant chapter of the
jython book would be a good idea.

> I am embedding Jython into a servlet container (tomcat) and am trying to
> figure out whether I can use a single interpreter for all requests

Yes you can use the same interpreter for all requests: see modjy for
an example of this.

[As an aside, is there a reason why you don't want to use modjy?]

> or I need
> to (a) put a big fat lock around the interpreter or (b) create an
> interpreter per request.

No, you don't have to do any do those things.

> As a point of reference, JRuby does an excellent job of describing the
> thread safety properties of their interpreter:

The jython book covers concurrency extensively.