Skip to content

Commit

Permalink
Merge pull request #318 from imagej/detach-init-thread
Browse files Browse the repository at this point in the history
Detach initialization QThread after ImageJ initialized
  • Loading branch information
gselzer authored Dec 10, 2024
2 parents b1d2b99 + 6d65400 commit 8fb1df2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ env:

jobs:
test-pip:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
name: ${{ matrix.platform }} (python ${{ matrix.python-version }})
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.12']
python-version: ['3.9', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name: napari-imagej-dev
channels:
- conda-forge
dependencies:
- python >= 3.8, < 3.13
- python >= 3.9, < 3.13
# Project dependencies
- confuse >= 2.0.0
- imglyb >= 2.1.0
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name: napari-imagej
channels:
- conda-forge
dependencies:
- python >= 3.8, < 3.13
- python >= 3.9, < 3.13
# Project depenencies
- confuse >= 2.0.0
- imglyb >= 2.1.0
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ classifiers = [
"Intended Audience :: Science/Research",
"Framework :: napari",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: Microsoft :: Windows",
"Operating System :: Unix",
"Operating System :: MacOS",
Expand All @@ -32,7 +32,7 @@ classifiers = [
]

# NB: Keep this in sync with environment.yml AND dev-environment.yml!
requires-python = ">=3.8, <3.13"
requires-python = ">=3.9, <3.13"
dependencies = [
"confuse >= 2.0.0",
"imglyb >= 2.1.0",
Expand Down
4 changes: 4 additions & 0 deletions src/napari_imagej/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def HashMap(self):
def Path(self):
return "java.nio.file.Path"

@JavaClasses.java_import
def Thread(self):
return "java.lang.Thread"

@JavaClasses.java_import
def Window(self):
return "java.awt.Window"
Expand Down
9 changes: 8 additions & 1 deletion src/napari_imagej/widgets/napari_imagej.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from napari.layers import Layer
from qtpy.QtCore import QModelIndex, QThread, Signal, Slot
from qtpy.QtWidgets import QVBoxLayout, QWidget
from scyjava import jstacktrace, when_jvm_stops
from scyjava import jstacktrace, when_jvm_stops, jvm_started

from napari_imagej import nij
from napari_imagej.java import jc
Expand Down Expand Up @@ -248,10 +248,17 @@ def run(self):
self._finalize_info_bar()
# Finalize EventSubscribers
self._finalize_subscribers()
# jc.Thread.detach()
except Exception as e:
# Handle the exception on the GUI thread
self.widget.ij_error_handler.emit(e)
return
finally:
# Detach JPype thread
# NB Java must NOT be touched on this thread after this call. See
# https://jpype.readthedocs.io/en/v1.5.0/userguide.html#python-threads
if jvm_started() and jc.Thread.isAttached():
jc.Thread.detach()

def _finalize_results_tree(self):
"""
Expand Down

0 comments on commit 8fb1df2

Please sign in to comment.