{"id":22515307,"url":"https://github.com/scijava/scyjava","last_synced_at":"2025-04-05T01:03:50.866Z","repository":{"id":28129508,"uuid":"113442144","full_name":"scijava/scyjava","owner":"scijava","description":"⚡ Supercharged Java access from Python ⚡","archived":false,"fork":false,"pushed_at":"2025-03-26T22:22:48.000Z","size":317,"stargazers_count":48,"open_issues_count":15,"forks_count":14,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-03-29T00:04:43.561Z","etag":null,"topics":["cross-language","integration","java","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/scyjava","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scijava.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-07T11:23:56.000Z","updated_at":"2025-03-26T22:22:45.000Z","dependencies_parsed_at":"2024-05-08T20:43:34.524Z","dependency_job_id":"647e5d01-9225-4408-8ae2-05e4f318af73","html_url":"https://github.com/scijava/scyjava","commit_stats":{"total_commits":340,"total_committers":13,"mean_commits":"26.153846153846153","dds":0.3970588235294118,"last_synced_commit":"18294c42cce110934e65aaae7a3f9a828d7e253f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijava%2Fscyjava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijava%2Fscyjava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijava%2Fscyjava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scijava%2Fscyjava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scijava","download_url":"https://codeload.github.com/scijava/scyjava/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271515,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-language","integration","java","python"],"created_at":"2024-12-07T03:29:36.766Z","updated_at":"2025-04-05T01:03:50.839Z","avatar_url":"https://github.com/scijava.png","language":"Python","readme":"[![build status](https://github.com/scijava/scyjava/actions/workflows/build.yml/badge.svg)](https://github.com/scijava/scyjava/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/scijava/scyjava/branch/main/graph/badge.svg?token=NLK3ADZUCU)](https://codecov.io/gh/scijava/scyjava)\n\nSupercharged Java access from Python.\n\nBuilt on [JPype](https://jpype.readthedocs.io/en/latest/)\nand [jgo](https://github.com/scijava/jgo).\n\n## Use Java classes from Python\n\n```python\n\u003e\u003e\u003e from scyjava import jimport\n\u003e\u003e\u003e System = jimport('java.lang.System')\n\u003e\u003e\u003e System.getProperty('java.version')\n'1.8.0_252'\n```\n\nTo pass parameters to the JVM, such as an increased max heap size:\n\n```python\n\u003e\u003e\u003e from scyjava import config, jimport\n\u003e\u003e\u003e config.add_option('-Xmx6g')\n\u003e\u003e\u003e Runtime = jimport('java.lang.Runtime')\n\u003e\u003e\u003e Runtime.getRuntime().maxMemory() / 2**30\n5.33349609375\n```\n\nSee the [JPype documentation](https://jpype.readthedocs.io/en/latest/)\nfor all the gritty details on how this wrapping works.\n\n## Use Maven artifacts from remote repositories\n\n### From Maven Central\n\n```python\n\u003e\u003e\u003e import sys\n\u003e\u003e\u003e sys.version_info\nsys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)\n\u003e\u003e\u003e from scyjava import config, jimport\n\u003e\u003e\u003e config.endpoints.append('org.python:jython-slim:2.7.2')\n\u003e\u003e\u003e jython = jimport('org.python.util.jython')\n\u003e\u003e\u003e jython.main([])\nJython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:12:24)\n[OpenJDK 64-Bit Server VM (JetBrains s.r.o)] on java1.8.0_152-release\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import sys\n\u003e\u003e\u003e sys.version_info\nsys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)\n\u003e\u003e\u003e from java.lang import System\n\u003e\u003e\u003e System.getProperty('java.version')\nu'1.8.0_152-release'\n```\n\n### From other Maven repositories\n\n```python\n\u003e\u003e\u003e from scyjava import config, jimport\n\u003e\u003e\u003e config.enable_headless_mode()\n\u003e\u003e\u003e config.add_repositories({'scijava.public': 'https://maven.scijava.org/content/groups/public'})\n\u003e\u003e\u003e config.endpoints.append('net.imagej:imagej:2.1.0')\n\u003e\u003e\u003e ImageJ = jimport('net.imagej.ImageJ')\n\u003e\u003e\u003e ij = ImageJ()\n\u003e\u003e\u003e formula = \"10 * (Math.cos(0.3*p[0]) + Math.sin(0.3*p[1]))\"\n\u003e\u003e\u003e ArrayImgs = jimport('net.imglib2.img.array.ArrayImgs')\n\u003e\u003e\u003e blank = ArrayImgs.floats(64, 16)\n\u003e\u003e\u003e sinusoid = ij.op().image().equation(blank, formula)\n\u003e\u003e\u003e print(ij.op().image().ascii(sinusoid))\n,,,--+oo******oo+--,,,,,--+oo******o++--,,,,,--+oo******o++--,,,\n...,--+ooo**oo++--,....,,--+ooo**oo++-,,....,,--+ooo**oo++-,,...\n ...,--++oooo++--,... ...,--++oooo++--,... ...,--++oooo++-,,...\n   ..,--++++++--,..     ..,--++o+++--,..     .,,--++o+++--,..\n   ..,,-++++++-,,.      ..,,-++++++-,,.      ..,--++++++-,,.\n    .,,--++++--,,.       .,,--++++--,,.       .,,--++++--,..\n    .,,--++++--,,.       .,,-+++++--,,.       .,,-+++++--,,.\n   ..,--++++++--,..     ..,--++++++--,..     ..,--++++++-,,..\n  ..,,-++oooo++-,,..   ..,,-++oooo++-,,..   ..,,-++ooo+++-,,..\n...,,-++oooooo++-,,.....,,-++oooooo++-,,.....,,-++oooooo+--,,...\n.,,,-++oo****oo++-,,,.,,,-++oo****oo+--,,,.,,,-++oo****oo+--,,,.\n,,--++o***OO**oo++-,,,,--++o***OO**oo+--,,,,--++o***OO**oo+--,,,\n---++o**OOOOOO**o++-----++o**OOOOOO*oo++-----++o**OOOOOO*oo++---\n--++oo*OO####OO*oo++---++oo*OO####OO*oo++---++o**OO####OO*oo++--\n+++oo*OO######O**oo+++++oo*OO######O**oo+++++oo*OO######O**oo+++\n+++oo*OO######OO*oo+++++oo*OO######OO*oo+++++oo*OO######OO*oo+++\n```\n\nSee the [jgo documentation](https://github.com/scijava/jgo) for more about Maven endpoints.\n\n## Convert between Python and Java data structures\n\n### Convert Java collections to Python\n\n```python\n\u003e\u003e\u003e from scyjava import jimport\n\u003e\u003e\u003e HashSet = jimport('java.util.HashSet')\n\u003e\u003e\u003e moves = {'jump', 'duck', 'dodge'}\n\u003e\u003e\u003e fish = {'walleye', 'pike', 'trout'}\n\u003e\u003e\u003e jbirds = HashSet()\n\u003e\u003e\u003e for bird in ('duck', 'goose', 'swan'): jbirds.add(bird)\n...\nTrue\nTrue\nTrue\n\u003e\u003e\u003e jbirds.isdisjoint(moves)\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: 'java.util.HashSet' object has no attribute 'isdisjoint'\n\u003e\u003e\u003e from scyjava import to_python as j2p\n\u003e\u003e\u003e j2p(jbirds).isdisjoint(moves)\nFalse\n\u003e\u003e\u003e j2p(jbirds).isdisjoint(fish)\nTrue\n```\n\n### Convert Python collections to Java\n\n```python\n\u003e\u003e\u003e squares = [n**2 for n in range(1, 10)]\n\u003e\u003e\u003e squares\n[1, 4, 9, 16, 25, 36, 49, 64, 81]\n\u003e\u003e\u003e squares.stream()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: 'list' object has no attribute 'stream'\n\u003e\u003e\u003e from scyjava import to_java as p2j\n\u003e\u003e\u003e p2j(squares).stream()\n\u003cjava object 'java.util.stream.ReferencePipeline.Head'\u003e\n```\n\n```python\n\u003e\u003e\u003e from scyjava import jimport\n\u003e\u003e\u003e HashSet = jimport('java.util.HashSet')\n\u003e\u003e\u003e jset = HashSet()\n\u003e\u003e\u003e pset = {1, 2, 3}\n\u003e\u003e\u003e jset.addAll(pset)\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nTypeError: No matching overloads found for java.util.Set.addAll(set), options are:\n\tpublic abstract boolean java.util.Set.addAll(java.util.Collection)\n\u003e\u003e\u003e from scyjava import to_java as p2j\n\u003e\u003e\u003e jset.addAll(p2j(pset))\nTrue\n\u003e\u003e\u003e jset.toString()\n'[1, 2, 3]'\n```\n\n## Available functions\n\n```\n\u003e\u003e\u003e import scyjava\n\u003e\u003e\u003e help(scyjava)\n...\nFUNCTIONS\n    add_java_converter(converter: scyjava._convert.Converter) -\u003e None\n        Add a converter to the list used by to_java.\n        :param converter: A Converter going from python to java\n\n    add_py_converter(converter: scyjava._convert.Converter) -\u003e None\n        Add a converter to the list used by to_python.\n        :param converter: A Converter from java to python\n\n    available_processors() -\u003e int\n        Get the number of processors available to the JVM.\n\n        This function is a shortcut for Java's\n        Runtime.getRuntime().availableProcessors().\n\n        :return: The number of available processors.\n        :raise RuntimeError: if the JVM has not yet been started.\n\n    enable_python_scripting(context)\n        Adds a Python script runner object to the ObjectService of the given\n        SciJava context. Intended for use in conjunction with\n        'org.scijava:scripting-python'.\n\n        :param context: The org.scijava.Context containing the ObjectService\n            where the PythonScriptRunner should be injected.\n\n    gc() -\u003e None\n        Do a round of Java garbage collection.\n\n        This function is a shortcut for Java's System.gc().\n\n        :raise RuntimeError: If the JVM has not started yet.\n\n    get_version(java_class_or_python_package) -\u003e str\n        Return the version of a Java class or Python package.\n\n        For Python package, uses importlib.metadata.version if available\n        (Python 3.8+), with pkg_resources.get_distribution as a fallback.\n\n        For Java classes, requires org.scijava:scijava-common on the classpath.\n\n        The version string is extracted from the given class's associated JAR\n        artifact (if any), either the embedded Maven POM if the project was built\n        with Maven, or the JAR manifest's Specification-Version value if it exists.\n\n        See org.scijava.VersionUtils.getVersion(Class) for further details.\n\n    is_arraylike(arr: Any) -\u003e bool\n        Return True iff the object is arraylike: possessing\n        .shape, .dtype, .__array__, and .ndim attributes.\n\n        :param arr: The object to check for arraylike properties\n        :return: True iff the object is arraylike\n\n    is_awt_initialized() -\u003e bool\n        Return true iff the AWT subsystem has been initialized.\n\n        Java starts up its AWT subsystem automatically and implicitly, as\n        soon as an action is performed requiring it -- for example, if you\n        jimport a java.awt or javax.swing class. This can lead to deadlocks\n        on macOS if you are not running in headless mode and did not invoke\n        those actions via the jpype.setupGuiEnvironment wrapper function;\n        see the Troubleshooting section of the scyjava README for details.\n\n    is_jarray(data: Any) -\u003e bool\n        Return whether the given data object is a Java array.\n\n    is_jvm_headless() -\u003e bool\n        Return true iff Java is running in headless mode.\n\n        :raise RuntimeError: If the JVM has not started yet.\n\n    is_memoryarraylike(arr: Any) -\u003e bool\n        Return True iff the object is memoryarraylike:\n        an arraylike object whose .data type is memoryview.\n\n        :param arr: The object to check for memoryarraylike properties\n        :return: True iff the object is memoryarraylike\n\n    is_version_at_least(actual_version: str, minimum_version: str) -\u003e bool\n        Return a boolean on a version comparison.\n        Requires org.scijava:scijava-common on the classpath.\n\n        Returns True if the given actual version is greater than or\n        equal to the specified minimum version, or False otherwise.\n\n        See org.scijava.VersionUtils.compare(String, String) for further details.\n\n    is_xarraylike(xarr: Any) -\u003e bool\n        Return True iff the object is xarraylike:\n        possessing .values, .dims, and .coords attributes,\n        and whose .values are arraylike.\n\n        :param arr: The object to check for xarraylike properties\n        :return: True iff the object is xarraylike\n\n    isjava(data) -\u003e bool\n        Return whether the given data object is a Java object.\n\n    jarray(kind, lengths: Sequence)\n        Create a new n-dimensional Java array.\n\n        :param kind: The type of array to create. This can either be a particular\n        type of object as obtained from jimport, or else a special code for one of\n        the eight primitive array types:\n        * 'b' for byte\n        * 'c' for char\n        * 'd' for double\n        * 'f' for float\n        * 'i' for int\n        * 'j' for long\n        * 's' for short\n        * 'z' for boolean\n        :param lengths: List of lengths for the array. For example:\n        `jarray('z', [3, 7])` is the equivalent of `new boolean[3][7]` in Java.\n        You can pass a single integer to make a 1-dimensional array of that length.\n        :return: The newly allocated array\n\n    jclass(data)\n        Obtain a Java class object.\n\n        Supported types include:\n\n        A. Name of a class to look up -- e.g. \"java.lang.String\" --\n           which returns the equivalent of Class.forName(\"java.lang.String\").\n\n        B. A static-style class reference -- e.g. String --\n           which returns the equivalent of String.class.\n\n        C. A Java object -- e.g. foo --\n           which returns the equivalent of foo.getClass().\n\n        Note that if you pass a java.lang.Class object, you will get back Class.class,\n        i.e. the Java class for the Class class. :-)\n\n        :param data: The object from which to glean the class.\n        :return: A java.lang.Class object, suitable for use with reflection.\n        :raise TypeError: if the argument is not one of the aforementioned types.\n\n    jimport(class_name: str)\n        Import a class from Java to Python.\n\n        :param class_name: Name of the class to import.\n        :return:\n            A pointer to the class, which can be used to\n            e.g. instantiate objects of that class.\n\n    jinstance(obj, jtype) -\u003e bool\n        Test if the given object is an instance of a particular Java type.\n\n        :param obj: The object to check.\n        :param jtype: The Java type, as either a jimported class or as a string.\n        :return: True iff the object is an instance of that Java type.\n\n    jstacktrace(exc) -\u003e str\n        Extract the Java-side stack trace from a Java exception.\n\n        Example of usage:\n\n            from scyjava import jimport, jstacktrace\n            try:\n                Integer = jimport('java.lang.Integer')\n                nan = Integer.parseInt('not a number')\n            except Exception as exc:\n                print(jstacktrace(exc))\n\n        :param exc: The Java Throwable from which to extract the stack trace.\n        :return: A multi-line string containing the stack trace, or empty string\n        if no stack trace could be extracted.\n\n    jvm_started() -\u003e bool\n        Return true iff a Java virtual machine (JVM) has been started.\n\n    jvm_version() -\u003e str\n        Gets the version of the JVM as a tuple, with each dot-separated digit\n        as one element. Characters in the version string beyond only numbers\n        and dots are ignored, in line with the java.version system property.\n\n        Examples:\n        * OpenJDK 17.0.1 -\u003e [17, 0, 1]\n        * OpenJDK 11.0.9.1-internal -\u003e [11, 0, 9, 1]\n        * OpenJDK 1.8.0_312 -\u003e [1, 8, 0]\n\n        If the JVM is already started, this function returns the equivalent of:\n           jimport('java.lang.System')\n             .getProperty('java.version')\n             .split('.')\n\n        In case the JVM is not started yet, a best effort is made to deduce\n        the version from the environment without actually starting up the\n        JVM in-process. If the version cannot be deduced, a RuntimeError\n        with the cause is raised.\n\n    memory_max() -\u003e int\n        Get the maximum amount of memory that the JVM will attempt to use.\n\n        This number will always be greater than or equal to memory_total().\n\n        In case the JVM was configured with -Xmx flag upon startup (e.g. using\n        the scyjava.config.set_heap_max function), the value will typically\n        correspond approximately, but not exactly, to the configured value.\n\n        This function is a shortcut for Java's Runtime.getRuntime().maxMemory().\n\n        :return: The maximum memory in bytes.\n        :raise RuntimeError: if the JVM has not yet been started.\n\n    memory_total() -\u003e int\n        Get the total amount of memory currently reserved by the JVM.\n\n        This number will always be less than or equal to memory_max().\n\n        In case the JVM was configured with -Xms flag upon startup (e.g. using\n        the scyjava.config.set_heap_min function), the initial value will typically\n        correspond approximately, but not exactly, to the configured value,\n        although it is likely to grow over time as more Java objects are allocated.\n\n        This function is a shortcut for Java's Runtime.getRuntime().totalMemory().\n\n        :return: The total memory in bytes.\n        :raise RuntimeError: if the JVM has not yet been started.\n\n    memory_used() -\u003e int\n        Get the amount of memory currently in use by the JVM.\n\n        This function is a shortcut for\n        Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory().\n\n        :return: The used memory in bytes.\n        :raise RuntimeError: if the JVM has not yet been started.\n\n    numeric_bounds(the_type: type) -\u003e Union[Tuple[int, int], Tuple[float, float], Tuple[NoneType, NoneType]]\n        Get the minimum and maximum values for the given numeric type.\n        For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),\n        whereas a Java double returns (float(-Double.MAX_VALUE), float(Double.MAX_VALUE)).\n\n        :param the_type: The type whose minimum and maximum values are needed.\n        :return:\n            The minimum and maximum values as a two-element tuple of int or float,\n            or a two-element tuple of None if no known bounds.\n\n    shutdown_jvm() -\u003e None\n        Shut down the JVM.\n\n        This function makes a best effort to clean up Java resources first.\n        In particular, shutdown hooks registered with scyjava.when_jvm_stops\n        are sequentially invoked.\n\n        Then, if the AWT subsystem has started, all AWT windows (as identified\n        by the java.awt.Window.getWindows() method) are disposed to reduce the\n        risk of GUI resources delaying JVM shutdown.\n\n        Finally, the jpype.shutdownJVM() function is called. Note that you can\n        set the jpype.config.destroy_jvm flag to request JPype to destroy the\n        JVM explicitly, although setting this flag can lead to delayed shutdown\n        times while the JVM is waiting for threads to finish.\n\n        Note that if the JVM is not already running, then this function does\n        nothing! In particular, shutdown hooks are skipped in this situation.\n\n        :raise RuntimeError: if this method is called while in Jep mode.\n\n    start_jvm(options=None) -\u003e None\n        Explicitly connect to the Java virtual machine (JVM). Only one JVM can\n        be active; does nothing if the JVM has already been started. Calling\n        this function directly is typically not necessary, because the first\n        time a scyjava function needing a JVM is invoked, one is started on the\n        fly with the configuration specified via the scijava.config mechanism.\n\n        :param options:\n            List of options to pass to the JVM.\n            For example: ['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']\n\n    to_java(obj: Any, **hints: Dict) -\u003e Any\n        Recursively convert a Python object to a Java object.\n\n        Supported types include:\n        * str -\u003e String\n        * bool -\u003e Boolean\n        * int -\u003e Integer, Long or BigInteger as appropriate\n        * float -\u003e Float, Double or BigDecimal as appropriate\n        * dict -\u003e LinkedHashMap\n        * set -\u003e LinkedHashSet\n        * list -\u003e ArrayList\n\n        There is typically one single destination conversion type and value that\n        makes sense. For example, Python str always converts to java.lang.String.\n        But in some cases, there are multiple options that can be controlled by\n        passing key/value pairs as hints. The base scyjava library includes:\n\n        * int + type='byte' -\u003e Byte\n        * int + type='short' -\u003e Short\n        * int + type='int' -\u003e Integer\n        * int + type='long' -\u003e Long\n        * int + type='bigint' -\u003e BigInteger\n        * float + type='float' -\u003e Float\n        * float + type='double' -\u003e Double\n        * float + type='bigdec' -\u003e BigDecimal\n\n        But the scyjava conversion framework is extensible and other\n        packages may introduce converters supporting additional hints.\n\n        In the absence of a hint, scyjava makes a best effort to use a sensible\n        destination type and value:\n\n        * int values in [-2**31, 2**31-1] convert to Integer\n        * int values in [-2**63, 2**63-1] but outside int range convert to Long\n        * int values outside Java long range convert to BigInteger\n        * conversion of int to Byte or Short must be requested via a hint\n        * float values in Float range convert to Float\n        * float inf, -inf, and nan convert to Float\n        * float values in Double range but outside float range convert to Double\n        * float values outside double range convert to BigDecimal\n\n        :param obj:\n            The Python object to convert.\n        :param hints:\n            An optional dictionary of hints, to help scyjava\n            make decisions about how to do the conversion.\n        :return: A corresponding Java object with the same contents.\n        :raise TypeError: if the argument is not one of the aforementioned types.\n\n    to_python(data: Any, gentle: bool = False) -\u003e Any\n        Recursively convert a Java object to a Python object.\n\n        Supported types include:\n        * String, Character -\u003e str\n        * Boolean -\u003e bool\n        * Byte, Short, Integer, Long, BigInteger -\u003e int\n        * Float, Double, BigDecimal -\u003e float\n        * Map -\u003e collections.abc.MutableMapping (dict-like)\n        * Set -\u003e collections.abc.MutableSet (set-like)\n        * List -\u003e collections.abc.MutableSequence (list-like)\n        * Collection -\u003e collections.abc.Collection\n        * Iterable -\u003e collections.abc.Iterable\n        * Iterator -\u003e collections.abc.Iterator\n\n        :param data:\n            The Java object to convert.\n        :param gentle:\n            If set, and the type cannot be converted, leaves\n            the data alone rather than raising a TypeError.\n        :return: A corresponding Python object with the same contents.\n        :raise TypeError:\n            if the argument is not one of the aforementioned types,\n            and the gentle flag is not set.\n\n    when_jvm_starts(f) -\u003e None\n        Registers a function to be called when the JVM starts (or immediately).\n        This is useful to defer construction of Java-dependent data structures\n        until the JVM is known to be available. If the JVM has already been\n        started, the function executes immediately.\n\n        :param f: Function to invoke when scyjava.start_jvm() is called.\n\n    when_jvm_stops(f) -\u003e None\n        Registers a function to be called just before the JVM shuts down.\n        This is useful to perform cleanup of Java-dependent data structures.\n\n        Note that if the JVM is not already running when shutdown_jvm is\n        called, then these registered callback functions will be skipped!\n\n        :param f: Function to invoke when scyjava.shutdown_jvm() is called.\n```\n\n## Troubleshooting\n\nOn macOS, attempting to use AWT/Swing from Python will cause a hang,\nunless you do one of two things:\n\n1.  Start Java in headless mode:\n\n    ```python\n    from scyjava import config, jimport\n    config.enable_headless_mode()\n    ```\n\n    In which case, you'll get `java.awt.HeadlessException` instead of a\n    hang when you attempt to do something graphical, e.g. create a window.\n\n2.  Or install [PyObjC](https://pyobjc.readthedocs.io/), specifically the\n    `pyobjc-core` and `pyobjc-framework-cocoa` packages from conda-forge,\n    or `pyobjc` from PyPI; and then do your AWT-related things inside of\n    a `jpype.setupGuiEnvironment` call on the main Python thread:\n\n    ```python\n    import jpype, scyjava\n    scyjava.start_jvm()\n    def hello():\n        JOptionPane = scyjava.jimport('javax.swing.JOptionPane')\n        JOptionPane.showMessageDialog(None, \"Hello world\")\n    jpype.setupGuiEnvironment(hello)\n    ```\n\n    In which case, the `setupGuiEnvironment` call will block the main Python\n    thread forever.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscijava%2Fscyjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscijava%2Fscyjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscijava%2Fscyjava/lists"}