Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jython multithreading

I started studying python a couple of month ago, then I found Jython.

Do threads work properly in Jython, since it doesn't have a GIL? If so, can you suggest a good book on concurrency (threading)?

like image 802
nassio Avatar asked May 13 '12 00:05

nassio


People also ask

Does Jython have Gil?

Jython lacks the global interpreter lock (GIL), which is an implementation detail of CPython. For CPython, the GIL means that only one thread at a time can run Python code.

Does Python 3 support multithreading?

Python doesn't support multi-threading because Python on the Cpython interpreter does not support true multi-core execution via multithreading.

How is Jython different from Python?

Difference between Python and Jython Reference implementation of Python, called CPython, is written in C language. Jython on the other hand is completely written in Java and is a JVM implementation. Standard Python is available on multiple platforms. Jython is available for any platform with a JVM installed on it.

Is Jython similar to Python?

Jython and Python are two versions of the same language, used for different contexts. Jython is a Java implementation of Python, which, in a nutshell, means it's Python running on a Java Virtual Machine (JVM) environment. It writes like Python, but it can access the full potential of Java libraries.


2 Answers

The best book I've encountered on multithreading is "Java Concurrency in Practice". It's very much concentrating on Java thread concurrency, and is both humbling and exciting when you start to understand the problems and the possibilities introduced by concurrency. The copy I bought a few years ago had some errata in the coding, though, which exacerbated an already brain-challenging subject: check out errata here: http://jcip.net/errata.html.

Although designed for Java developers wishing to venture into concurrency (which by the way includes anyone who's ever used a GUI interface of any kind), I'm sure the technical difficulties and subtleties outlined in the book apply to any implementation of concurrency.

By the way, I also love Jython and can confirm that anything concurrency-wise that you can do in Java you can apparently do in Jython. However, there is a caveat: concurrency can be for asynchronous programming (including GUI) and/or for performance. If for the latter you have a problem, in my opinion: Jython in my experience runs about 10 x slower than the equivalent Java program.

What this means is that your more demanding Jython modules will have to call something other than Jython for the number-crunching tasks. At the same time, Jython up to now* has not had Python's multiprocessing module, so inter-process communications are out, unless you venture into the dreaded territory of RMI. You're more of a man/woman than I if you take that option. But everything's OK: please refer to "The Definitive Guide to Jython" at http://www.jython.org ... chapter 19 is a sort of whistle-stop intro to concurrency, and chapter 10 is about integrating Java and Jython (hint: it's absurdly easy).

  • interesting: a quick glimpse at the Jython site shows that, just 10 days ago, 17/05/12, version 2.7a1 was released... an "Alpha" release. This should contain the multiprocessing module, which came in with Python 2.6. Wd be interesting to check this: if so it presumably gives you the exciting option of linking Jython and CPython processes (update later: sadly it appears for the moment that this is not so - the module name "multiprocessing" was not recognised when I tried)...

PS a final word: most experts who know much more about these things than I say that Moore's law is being superseded in importtance by Amdahl's law, which in short means that the daunting challenge of programming stable and scalable true concurrent programs will be unavoidable in the future. Exactly how easy true (i.e. thread) concurrency can be made with the use of clever code analysis tools I can't say but investment in this subject and the fascinating, intellectual new disciplines of reasoning imposed by concurrency will probably pay off... if you like a challenge.

like image 119
mike rodent Avatar answered Sep 28 '22 19:09

mike rodent


Yes, with Jython you've real multi-threading. Jython (JPython successor's) is an implementation of Python that runs in the JVM. One of the main differences between Jython and the original project is that the first doesn't have the GIL and implements a real multi-threading support based on the JVM's implementation.

I'd suggest you to take a look to this book and the OReilly's one.

like image 37
FlaPer87 Avatar answered Sep 28 '22 17:09

FlaPer87