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

jpype fails when using negbio in flask #27

Closed
staplet3 opened this issue Mar 8, 2019 · 3 comments
Closed

jpype fails when using negbio in flask #27

staplet3 opened this issue Mar 8, 2019 · 3 comments

Comments

@staplet3
Copy link

staplet3 commented Mar 8, 2019

Hey guys, I wrapped NegBio in a flask app and had JPype fail within the Stanford Dependencies python library. I had to modify the JPypeBackend.py file to attach the thread to the JVM. I know you don't maintain this source code, but just a heads up. Changes start on line 45:

num_thread = jpype.isThreadAttachedToJVM()
if num_thread is not 1:
     jpype.attachThreadToJVM()

JPypeBackend.py.zip
Attached the modified file here

@yfpeng
Copy link
Collaborator

yfpeng commented Mar 8, 2019

Thank you! I have added your comment on the Wiki page.

@kaushikacharya
Copy link
Contributor

kaushikacharya commented Jun 15, 2019

I think the proper usage would be

if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()

as isThreadAttachedToJVM() returns boolean
https://jpype.readthedocs.io/en/devel/api.html#jpype.isThreadAttachedToJVM
https://github.com/jpype-project/jpype/blob/master/jpype/_core.py#L211

Otherwise as the following shows,
jpype.isThreadAttachedToJVM() is not 1
will always return True irrespective of whether the function returns True or False.

>>> False is not 1
True
>>> True is not 1
True
>>> False is not 0
True
>>> True is not 0
True

@yfpeng
Copy link
Collaborator

yfpeng commented Jun 23, 2019

Thank you! I have updated the wiki.

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

No branches or pull requests

3 participants