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 working once and crashing second time in Django #395

Closed
talatccan opened this issue Jan 12, 2019 · 4 comments
Closed

Jpype working once and crashing second time in Django #395

talatccan opened this issue Jan 12, 2019 · 4 comments

Comments

@talatccan
Copy link

talatccan commented Jan 12, 2019

Hi,

I have python script which using jpype and i integrated it to django. Its working without problem when i run server the first time. But server is crashing by itself when i post second input. Even there is no exception. I dont know what to do.

```
JAR_PATH = 'bin\morp.jar'
if not jp.isJVMStarted():
    jp.startJVM(jp.getDefaultJVMPath(), "-Djava.class.path=%s" % JAR_PATH)
else:
    pass

MorpClass = jp.JClass('morp.Morp.MorpClass')
Paths = jp.JClass('java.nio.file.Paths')

createW = MorpClass.createWithDefaults()
analysis = createW .analyzeSentence(sentence)
results = createW .disambiguate(sentence, analysis).bestAnalysis()
analysis_result = ''
for i in results:
    analysis_result += str(i)
    analysis_result += ' -- '
print(analysis_result)
```
@Thrameos
Copy link
Contributor

This question was never addressed. Is it still an issue or of interest?

@kaushikacharya
Copy link

#81 (comment)
baztian's answer might help.

Django applications are multithreaded. Please make sure to call jpype.attachThreadToJVM() before invoking jpype functionality.

@Thrameos
Copy link
Contributor

Okay if that is the case then a switch to JPype 0.7.0 is in order. We dropped the silly requirement that the threads be attached manually. There is no way for a user to control when a third party gets a hold of a thread and touches Java resources. This was the plague of PyCharm and Spyder. Thus we now automatically make the connection when needed.

@Thrameos
Copy link
Contributor

This issue should now be resolved with the release of 0.7.0. Closing this thread. If there is still an issue please file another ticket.

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