Skip to content

Commit

Permalink
Add check for running JVM when adding callbacks
Browse files Browse the repository at this point in the history
This commit adds a check to see if the JVM has already been started.
If True, then run the callback immediately instead of appending to the
global callbacks list. This aligns with the callback mechanism in
scyjava.
  • Loading branch information
elevans committed Jul 15, 2024
1 parent 735304b commit e00da05
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,13 @@ def when_imagej_starts(f) -> None:
as its sole argument, and called as the final action of the
init function before it returns or blocks.
"""
# Add function to the list of callbacks to invoke upon start_jvm().
global _init_callbacks
_init_callbacks.append(f)
if sj.jvm_started():
# JVM already started, invoke callback immediately.
f()
else:
# Add function to the list of callbacks to invoke upon start_jvm().
global _init_callbacks
_init_callbacks.append(f)


def imagej_main():
Expand Down

0 comments on commit e00da05

Please sign in to comment.