Skip to content

Fix #331: Don't call Py_Initialize() in PyInit__jpype() to support Python 3.7#332

Merged
marscher merged 1 commit intojpype-project:masterfrom
vstinner:patch-1
Jun 21, 2018
Merged

Fix #331: Don't call Py_Initialize() in PyInit__jpype() to support Python 3.7#332
marscher merged 1 commit intojpype-project:masterfrom
vstinner:patch-1

Conversation

@vstinner
Copy link
Copy Markdown
Contributor

Since Python 3.7, calling Py_Initialize() twice triggers a fatal error.

Simply remove the Py_Initialize() call from PyInit__jpype(), since it is just useless.

…thon 3.7

Since Python 3.7, calling Py_Initialize() twice triggers a fatal error.

Simply remove the Py_Initialize() call from PyInit__jpype(), since it is just useless.
@vstinner
Copy link
Copy Markdown
Contributor Author

cc @hroncok

@vstinner
Copy link
Copy Markdown
Contributor Author

I tested manually https://github.com/konlpy/konlpy test suite with this JPype fix: Python doesn't crash anymore! My PR fixed my bug.

@vstinner
Copy link
Copy Markdown
Contributor Author

I also reported the issue upstream: https://bugs.python.org/issue33932

@vstinner
Copy link
Copy Markdown
Contributor Author

cc @marscher

Note: I'm a CPython core developer.

@marscher marscher merged commit d3be80f into jpype-project:master Jun 21, 2018
@marscher
Copy link
Copy Markdown
Member

I trust you and my CI, was just waiting for it to pass. Thank you very much for your patch!

@marscher
Copy link
Copy Markdown
Member

I guess we need to cut this jpype release soon...

@Thrameos
Copy link
Copy Markdown
Contributor

Does the PyEval_InitThreads() belong in the module initialization as well? The CPython documentation wasn't clear if this was a module thing or just part of the python startup.

@vstinner vstinner deleted the patch-1 branch June 22, 2018 06:43
@vstinner
Copy link
Copy Markdown
Contributor Author

Does the PyEval_InitThreads() belong in the module initialization as well?

You have to keep this call.

We enhanced the documentation in Python 3.7:
https://docs.python.org/dev/c-api/init.html
"Note: The following functions should not be called before Py_Initialize(): (...) PyEval_InitThreads()."

Moreover, we did another change in Python 3.7:
" void PyEval_InitThreads(): (...) Changed in version 3.7: This function is now called by Py_Initialize(), so you don’t have to call it yourself anymore."

On Python 3.6 and older, it's a good thing to call this function to prevent race conditions when spawning threads in C which then uses the Python API.

@vstinner
Copy link
Copy Markdown
Contributor Author

Changed in version 3.7: This function is now called by Py_Initialize(), so you don’t have to call it yourself anymore.

Oh, and if you are curious, I wrote an article about this specific change :-) https://vstinner.github.io/python37-gil-change.html

@marscher
Copy link
Copy Markdown
Member

That's very cool! Congrats for nailing this nasty one down 😎

@Thrameos
Copy link
Copy Markdown
Contributor

@marscher We likely need to hit the known defect on the arrays considering everything with the same size as being directly convertible before cutting a release. But it will be a week or two before I can get back to that.

@vstinner
Copy link
Copy Markdown
Contributor Author

While removing the Py_Initialize() is safe and fix a bug in Python 3.7rc1, FYI I fixed the future Python 3.7.0 final to allow again to call Py_Initialize() twice. But Nick Coghlan still plans to deprecate this behaviour, in the future calling Py_Initialize() twice will fail (as Python 3.7rc1).

@rapgro rapgro mentioned this pull request Nov 5, 2018
6 tasks
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.

3 participants