% State of Jython % Jim Baker % jim.baker@{python.org, rackspace.com}
- Background on Jython
- Jython 2.7.0 is under very active development
- Should have a final release by Q4
- Race through some of these changes in this status update
- Core developer of Jython
- Co-author of Definitive Guide to Jython from Apress
- Software developer at Rackspace
- Formerly, founding team member, Ubuntu Juju
- Lecturer in CS at Univ of Colorado at Boulder
- Implementation of Python for the Java platform
- Compiles to Java bytecode
- Under development since 1997
- Language changes - easy and completed early in the development cycle
- Runtime and libraries - mostly easy, some continuing work
- Ecosystem - current focus
- Java 7 JVM is now the minimum version - get to use
AutoCloseable
- Enable mixing Python and Java types in the bases of a class when using a metaclass
- Added support for buffer and memoryview
- Console and encoding support, such as unicodedata, IDNA, and CJK support
- Relative star imports, which seems to impact a number of interesting projects.
- Many, many small fixes (bz2 support, including tarfile, ...)
- Now in Jython trunk
- Reimplements Python socket/select/ssl modules with Netty 4
- (Netty is a popular performant event loop networking framework for the JVM)
- Jython socket support is now very close to what is seen in Windows
class PythonInboundHandler(ChannelInboundHandlerAdapter):
def __init__(self, sock):
self.sock = sock
def channelActive(self, ctx):
self.sock._notify_selectors()
ctx.fireChannelActive()
def channelRead(self, ctx, msg):
msg.retain() # bump ref count
self.sock.incoming.put(msg)
self.sock._notify_selectors()
ctx.fireChannelRead(msg)
...
-
All differences between nonblocking vs blocking with optional timeouts managed in one place
-
All sockets can be selected on, regardless of blocking/nonblocking state
@raises_java_exception
def _handle_channel_future(self, future, reason):
def workaround_jython_bug_for_bound_methods(_):
self._notify_selectors()
future.addListener(workaround_jython_bug_for_bound_methods)
if self.timeout is None:
return future.sync()
elif self.timeout:
self._handle_timeout(future.await, reason)
if not future.isSuccess():
raise future.cause()
return future
else:
return future
- Popular client for working with HTTP/HTTPS with beautiful API
- Now works with Jython!
- Handy since it's used by pip
- socket-reboot enables requests
- pip now works (again!) but requires a branch for the moment, including wheel support
- Dependency is completing a small PR against html5lib-python so that it doesn't use isolated UTF-16 surrogates in literals, since this is not actually legal unicode, nor does it work in Jython's UTF-16 based representation.
- Ironically this usage is to detect such illegal use in input streams
- Will also support virtualenv and tox
- Plan to bundle pip support via ensurepip backport
- Performance tuning of Jython's port of sre
- Currently requires expansion of UTF-16 encoded strings into codepoints array
- Memoization of this expansion means beautifulsoup now works with decent performance (no extra
$O(n)$ factor) - May have implications for web frameworks
- Develop tooling outside the usual release schedule and problems of being in core
- Clamp - improve integration of Jython from Java
- Jiffy - support cffi for Jython
- Fireside - blazing fast WSGI bridge for servlet containers
- Logbridge - Use simple logging facade for Java as a Python logging handler
- What else?
- Precise integration with Java
- Java can directly import Python modules (at last!)
- Integrates with setuptools to produce jars
- Includes future integration as well with Maven via Aether.
- Sprint Saturday to add Java annotation as class and method decorators
from java.io import Serializable
from java.util.concurrent import Callable
class BarClamp(Callable, Serializable):
def call(self):
return 42
To import a Python class that you want to import into Java, add a couple of lines:
from java.io import Serializable
from java.util.concurrent import Callable
from clamp import clamp_base
BarBase = clamp_base("bar") # Java package prefix
class BarClamp(BarBase, Callable, Serializable):
def call(self):
return 42
Key insight: ahead-of-time builds through setuptools to produce a jar for Java linkage:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages
setup(
name = "clamped",
version = "0.1",
packages = find_packages(),
install_requires = ["clamp>=0.3"],
clamp = ["clamped"],
)
Simply import clamped Python classes into Java code!
import bar.clamped.BarClamp;
public class UseClamped {
public static void main(String[] args) {
BarClamp barclamp = new BarClamp();
try {
System.out.println("BarClamp: " +
barclamp.call());
} catch (Exception ex) {
System.err.println("Exception: " + ex);
}
}
}
- Provide a CFFI backend for Jython
- Pure vaporware
- Cursory examination of
cffi.backend_ctypes
suggests effort is straightforward/modest
- Started to collect examples for cross-implementation support
- Example: surrogate support
- Add JyNI jar to the Java classpath enables C extension API support
- Works for a number of packages, but need to add GC support (!) for anything real
- Sprinting on JyNI this Monday in Aachen
- We have nearly completed bug triage
- Complete beta 4 (final beta)
- Release candidates as needed
- Mostly around performance, Java integration, and of course the usual bug fixes
- Python bytecode compiler for Android, large complex methods
- More hooks for Java integration
- Integrating Zippy to provide PyPy-like performance (requires Graal JVM)
- Java 9 may also add more features to optimize dynamic languages
- Comes up periodically!
- Would be nice for unicode strings and bytestrings to have direct correspondence to Java
- Remove code!
- Plan to kickoff development at PyCon in Montreal Spring 2015
- Release schedule: we will get there at some point!