JPype 1.0.2 update, libraries for accessing Java classes from Python

Available new layer release JPype 1.0.2, which allows you to organize full access of Python applications to Java class libraries. With JPype from Python, you can use Java-specific libraries to create hybrid applications that combine Java and Python code. Unlike Jython, integration with Java is achieved not through the creation of a Python variant for the JVM, but through interaction at the level of both virtual machines using shared memory. The proposed approach allows not only to achieve good performance, but also provides access to all CPython and Java libraries. Project code spreads licensed under Apache 2.0.

Major changes:

  • Added a cache to method calls to avoid overload resolution, greatly reducing the performance impact of method resolution, especially if the same overload is called many times, as in loops.
  • From 4 to 100 times, depending on the type of data, the transfer of lists, tuples and buffers to arrays of Java primitives is accelerated. The transformation uses optimized in-memory buffer handling instead of the Sequence API. When a Python buffer is encountered, only the first element is checked for conversion, since these buffers are homogeneous.
  • Handling shutdown operations (implemented in JPype 1.0.0, but skipped when preparing the changelog). JPype now calls the JVM's shutdown procedure, which tries to gracefully exit. This results in several behavioral changes. Non-background threads (proxy calls) can now keep the JVM open until they are terminated. Proxy calls will process shutdown until the call is completed, but will receive an abort message. Files are now closed properly and flushed to disk if the threads handle the exception properly. Resource cleanup hooks and finalizers are executed. When threads are spawned, AtExit hooks are called. Through the daemon, automatic thread attachment is implemented when using the JVM from Python. The erroneous code that fails to properly handle thread cleanup is likely to hang on shutdown. Additional documentation is in the user guide.
  • The wrapper for Throwable was getting a wrapper for Object instead of the expected result, leading to strange conversions from Python classes.
  • Fixed typos in the import system that resulted in a '"jname" not found' error.
  • Ensured correct promotion of "^C" in KeyboardInterrupt.
  • Fixed character issue with Python 3.5.3. PySlice_Unpack was introduced in a subsequent patch release (3.5.4) and should not have been used.
  • Fixed a crash with numpy.linalg.inv. The issue has been traced back to thread interaction between the JVM and some variants of numpy. The suggested solution is to call numpy.linalg.inv before starting the JVM.

Source: opennet.ru

Add a comment