Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if the VM was already open, provide a stacktrace where it was started #502

Closed
wants to merge 5 commits into from

Conversation

cmacdonald
Copy link
Contributor

No description provided.

@tshirtman
Copy link
Member

tshirtman commented Apr 8, 2020

hm, interesting, but it does feel a bit hacky, especially doing it for any run, maybe it should be behind a debug option/flag? maybe controlled by the debug log level? (though that doesn't seem great either). Maybe a more generic way to do it would be to allow a hook to be ran when the jvm starts, so the user would be able to get a pdb there and explore the frames that got them there themselves?

edit: also, i see you have the commit for autocloseable, and then a revert for it in there, if we are to merge that, i'd rather see these two removed through rebasing, or the whole thing squashed on merge, to avoid this making the history more confusing.

@cmacdonald
Copy link
Contributor Author

I failed to rebase earlier. Could we resort to a new PR?

@tshirtman
Copy link
Member

sure.

@tshirtman
Copy link
Member

arf, i just tried my idea of a startup hook system, but it doesn't work because importing reflect is triggering the creation of the jvm, and reflect is imported in the __init__.py (to allow importing stuff from it instead of nested modules). For this reason, it's not possible to expose a register_startup_hook function anywhere in the package, as importing it does trigger the starting of the jvm, defeating the purpose of a startup hook.

I guess that's not a very pressing feature, so no need to break things left and right to make it work, i'll wait for better ideas :).

@cmacdonald
Copy link
Contributor Author

and I bet you wanted to know where the JVM had started...

@tshirtman
Copy link
Member

haha indeed, but i cheated and added a default hook in my list and put pdb inside it, and indeed that avoided me a lot of research.

@tshirtman
Copy link
Member

my current "best idea" is to use env varibles, something like

in say module.py

def hook():
     # this function will be called

in shell

export JNIUS_VM_STARTUP_HOOK="module.hook"

And when in jnius, if that env var is detected, use importlib to load that symbol and call it.

@cmacdonald
Copy link
Contributor Author

hi, I think this is overcomplicating things. If a dev is developing code, they get the exception, and they want to know where that happened. The formatting of a traceback in the exception isnt great, but it does the trick cheaply.

Your solution would involve restarting an additional time to add the debugger, when the dev could have already fixed the error by inspecting the stacktrace the first time?

@tshirtman
Copy link
Member

true, i agree it's more practical, but it does feel dirty. and it's a bit confusing that the traceback displayed on the second start is the one from the first run, I'll think some more about it.

@cmacdonald
Copy link
Contributor Author

I think both are shown; could the previous traceback be appended to the first? (I found it difficult to change this in Python, as the stacktraces arent attached to the Exception.)

The error is a coding error in one of the two places, so both stacktraces are valid/useful information.

Or is there the idea of exceptions with nested causes (each with a stacktrace)?

Copy link
Member

@tshirtman tshirtman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this is certainly a useful feature, and i don't think anymore the way it's implemented is so bad it should prevent the feature to be merged, i wish there was a more generic way to do this, but it's not horrible.

@tshirtman
Copy link
Member

rebase/merged localy in 384ae08

@tshirtman tshirtman closed this May 2, 2020
@cmacdonald cmacdonald deleted the vm_started_trace branch May 2, 2020 18:02
@cmacdonald
Copy link
Contributor Author

Thanks @tshirtman

AndreMiras added a commit to AndreMiras/pyjnius that referenced this pull request May 2, 2020
Simple `check_vm_running()` for a single source of truth, refs:
kivy#502 (review)
AndreMiras added a commit to AndreMiras/pyjnius that referenced this pull request May 2, 2020
Simple `check_vm_running()` for a single source of truth, refs:
kivy#502 (review)
tshirtman added a commit that referenced this pull request May 3, 2020
Full Changelog: 1.2.1...1.3.0

Implemented enhancements:
- (#483) allow passing a `signature` argument to constructors, to force selection of the desired one
- (#497) support for more "dunder" methods/protocols on compatible interfaces than just `__len__`, and allow users to provide their own.
- (#500) allow ignoring private methods and fields in autoclass (both default to False)
- (#503) auto detect java_home on OSX, using `/usr/libexec/java_home` (if JAVA_HOME is not declared)
- (#514) writing to static fields (and fix reading from them)
- (#517) make signature exceptions more useful
- (#502) provide a stacktrace for where JVM was started.
- (#523) expose the class's class attribute
- (#524) fix handling of Java chars > 256 in Python3
- (#519) Always show the exception name

Fixed bugs:
- (#481) wrong use of strip on JRE path
- (#465) correct reflection to avoid missing any methods from parent classes or interfaces
- (#508) don't had error details with a custom exception when java class is not found
- (#510) add missing references to .pxi files in setup.py, speeding up recompilation
- (#518) ensure autoclass prefers methods over properties
- (#520) improved discovery of libjvm.so + provide a workaround if it doesn't work

Documentation:
- (#478) document automatic Thread detach feature
- (#512) document the requirement to keep reference to object/functions passed to java, for as long as it might use them
- (#521) fix inheritance in example

Many thanks to the contributors that stepped up to help this release, it wouldn't have been possible without them.

Craig Macdonald, Gabriel Pettier, Jim, André Miras, Young Ryul Bae, yyang, Pascal Chambon, Kevin Ollivier, Guillaume Gay, Christian M. Salamut, collaborated for this release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants