Size: 187
Comment:
|
Size: 1820
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
http://www.jython.org/index.html | * http://www.jython.org/index.html * wget https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar * https://wiki.python.org/jython/UserGuide |
Line 5: | Line 7: |
* wget https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar | {{{#!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 }}} == 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. |
jython
Python for the Java platform (2.7)
1 wget https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar
2 sudo apt update
3 sudo apt upgrade
4 sudo apt install openjdk-17-jdk
5 echo "print(\"Hello jython\")" > hello.py
6 java -jar jython-standalone-2.7.1.jar hello.py
7
8 alias jython="java -jar jython-standalone-2.7.1.jar"
9 jython hello.py
GUI app
app.py
1 from javax.swing import JButton, JFrame
2
3 frame = JFrame('Hello, Jython!',
4 defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
5 size = (300, 300)
6 )
7
8 def change_text(event):
9 print 'Clicked!'
10
11 button = JButton('Click Me!', actionPerformed=change_text)
12 frame.add(button)
13 frame.visible = True
1 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.