From: Ype K. <yk...@xs...> - 2001-07-31 18:40:20
|
John, >I have not yet been able to find an answer to this >question. I understand that the development aim >behind Jython is to be closely matched to cPython. >However, this would be an interesting place for Jython >to diverge from cPython. > >CPython implements a global interpreter lock which >prevents multiple threads from running on multiple >CPUs. A single multi-threaded cPython process makes >little use of the extra processing horsepower >available on enterprise class SMP server >configurations. > >The java threading model supports both OS native >threads and "green" threads depending on the JVM used. > If Jython is based on the Java threading model. With >a fair degree of good software design, it is actually >possible for a multi-threaded Jython process to run >faster than the corresponding cPython process. So the >factor 2 which comes up so frequently when comparing >the speed of Jython to cPython is somewhat irrelevant >and largely depends on the context of which it is >used. > >If Jython is based on the Java threading model, a >server comprised of 4 CPUs could potentially out pace >the cPython process by a factor of 2. I feel this is >a very important distinction between the two varieties >of python, and for enterprise class systems, the use >of Jython may be preferred. Have a look at PyThread.java in the sources (org.python.core iirc) and admire its simplicity: Python's threading model is pretty close to Java's, and this is no coincidence. Most of what it does is overriding java.lang.Thread.run() to call the python function provided as argument to the python standard function to start a new thread. This makes Jython threading as good as the threading provided by the JVM you are using. When the JVM uses multiprocessor threading, so will Jython. There are a few small differences, ao. you cannot catch java.lang.InterruptedException in Jython and Python threads should end in system.exit(), which throws a Python exception. Also you may have to register (atexit module) a Python exit function that calls the JVM exit function from java.lang.RunTime. Have fun, Ype P.S. Installing the sources is an option in the installer that will add the org directory to your installation. Default is off, which is a pity I think. |