= jython = Python for the Java platform (2.7) * http://www.jython.org/index.html * https://www.jython.org/installation * https://wiki.python.org/jython/UserGuide {{{#!highlight sh wget https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar sudo apt update sudo apt upgrade sudo apt install openjdk-17-jdk echo "print(\"Hello jython\")" > hello.py java -jar jython-standalone-2.7.1.jar hello.py alias jython="java -jar jython-standalone-2.7.1.jar" jython hello.py # Hello jython jython -V # Jython 2.7.1 }}} == Installation == {{{#!highlight sh wget https://repo1.maven.org/maven2/org/python/jython-installer/2.7.3/jython-installer-2.7.3.jar java -jar jython-installer-2.7.3.jar --console # Welcome to Jython ! # You are about to install Jython version 2.7.3 # (at any time, answer c to cancel the installation) # For the installation process, the following languages are available: English, German # Please select your language [E/g] >>> E # Do you want to read the license agreement now ? [y/N] >>> # Do you accept the license agreement ? [Y/n] >>> # The following installation types are available: # 1. All (everything, including sources) # 2. Standard (core, library modules, demos and examples, documentation) # 3. Minimum (core) # 9. Standalone (a single, executable .jar) # Please select the installation type [ 1 /2/3/9] >>> 2 # Do you want to install additional parts ? [y/N] >>> # Do you want to exclude parts from the installation ? [y/N] >>> # Please enter the target directory >>> /home/vagrant/jython # Unable to find directory /home/vagrant/jython, create it ? [Y/n] >>> # Your java version to start Jython is: Debian / 17.0.6 # Your operating system version is: Linux / 5.10.0-20-amd64 # Summary: # - mod: true # - demo: true # - doc: true # - src: false # - ensurepip: true # - JRE: /usr/lib/jvm/java-17-openjdk-amd64 # Please confirm copying of files to directory /home/vagrant/jython [Y/n] >>> # 70 % # Generating start scripts ... # Installing pip and setuptools # 90 % # DEPRECATION: A future version of pip will drop support for Python 2.7. # Looking in links: /tmp/tmpaSLvLl # Collecting setuptools # Collecting pip # Installing collected packages: setuptools, pip # Successfully installed pip-19.1 setuptools-41.0.1 # 100 % # Do you want to show the contents of README ? [y/N] >>> # Congratulations! You successfully installed Jython 2.7.3 to directory /home/vagrant/jython. PATH=$PATH:/home/vagrant/jython/bin/ jython -V # Jython 2.7.3 pip2.7 install cherrypy # DEPRECATION: A future version of pip will drop support for Python 2.7. # Collecting cherrypy # Downloading https://files.pythonhosted.org (...) jython # Jython 2.7.3 (tags/v2.7.3:5f29801fe, Sep 10 2022, 18:52:49) # [OpenJDK 64-Bit Server VM (Debian)] on java17.0.6 # Type "help", "copyright", "credits" or "license" for more information. # >>> import cherrypy # >>> cherrypy.__version__ # '17.4.2' }}} == GUI app == * https://jython.readthedocs.io/en/latest/GUIApplications/ === app.py === {{{#!highlight python from javax.swing import JButton, JFrame frame = JFrame('Hello, Jython!', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (300, 300) ) def change_text(event): print 'Clicked!' button = JButton('Click Me!', actionPerformed=change_text) frame.add(button) frame.visible = True }}} {{{#!highlight sh java -jar jython-standalone-2.7.1.jar app.py }}} == GIL (Global Interpreter Lock) == https://jython.readthedocs.io/en/latest/chapter19/#no-global-interpreter-lock No Global Interpreter Lock 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. Again, Jython does not have the straightjacket of the GIL. This is because all Python threads are mapped to Java threads and use standard Java garbage collection support (the main reason for the GIL in CPython is because of the reference counting GC system). The important ramification here is that you can use threads for compute-intensive tasks that are written in Python.