[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

bpo-34008: Allow to call Py_Main() after Py_Initialize() #8043

Merged
merged 3 commits into from Jul 20, 2018
Merged

bpo-34008: Allow to call Py_Main() after Py_Initialize() #8043

merged 3 commits into from Jul 20, 2018

Conversation

Copy link
Member

vstinner commented Jul 2, 2018

Py_Main() can again be called after Py_Initialize(), as in Python 3.6. The new configuration is ignored, except of _PyMainInterpreterConfig.argv which is used to update sys.argv.

https://bugs.python.org/issue34008

Copy link
Contributor

hroncok commented Jul 2, 2018

I will test this with fontforge to see if it fixes its problem.

Copy link
Contributor

hroncok commented Jul 2, 2018

The abort is gone, however now I get:

fontforge -lang=py -script apply_featurefile.py Lohit-Assamese.sfd Lohit-Assamese.fea
Copyright (c) 2000-2014 by George Williams. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Based on sources from 09:18 UTC  2-Jul-2018-ML-D.
 Based on source from git with hash: 
Traceback (most recent call last):
  File "apply_featurefile.py", line 23, in <module>
    if len(sys.argv) < 3:
AttributeError: module 'sys' has no attribute 'argv'

Copy link
Contributor

ncoghlan commented Jul 4, 2018

D'oh, that's what I was afraid of: fontforge is relying on the fact that Py_Main() still runs all of its command line processing, even if Py_Initialize() becomes a no-op: https://github.com/python/cpython/blob/3.6/Modules/main.c#L703

While I suspect it will leak a bit of memory (but hopefully not segfault on shutdown), it's likely worth trying a variant of Victor's patch that calls pymain_init_python_main even when the runtime is already initialized.

Copy link
Contributor

hroncok commented Jul 4, 2018

Can you please point me to Victor's patch? I'm a bit lost in multiple places this is being discussed 😄

Copy link
Contributor

ncoghlan commented Jul 4, 2018

I just meant this PR :)

Copy link

ilovezfs commented Jul 5, 2018

It looks like VTK is also affected by the bug this is fixing.

/usr/local/Cellar/vtk/8.1.1/bin/vtkpython -c exit()
Fatal Python error: _Py_InitializeCore: main interpreter already initialized

Current thread 0x00007fff7507e000 (most recent call first):

If I rebuild Python 3.7 with this PR, then that error goes away.

Py_Main() can again be called after Py_Initialize(), as in Python
3.6. The new configuration is ignored, except of
_PyMainInterpreterConfig.argv which is used to update sys.argv.
Copy link
Contributor

hroncok commented Jul 20, 2018

this fixes the fontforge issue

Copy link
Contributor

ncoghlan left a comment

Choose a reason for hiding this comment

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

LGTM!

vstinner merged commit fb47bca into python:master Jul 20, 2018
vstinner deleted the init_pymain branch July 20, 2018 15:34
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 20, 2018
Py_Main() can again be called after Py_Initialize(), as in Python
3.6. The new configuration is ignored, except of
_PyMainInterpreterConfig.argv which is used to update sys.argv.
(cherry picked from commit fb47bca)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Copy link

GH-8352 is a backport of this pull request to the 3.7 branch.

Copy link
Member Author

Thanks for the review @ncoghlan! I merged my PR to master and will backport it to 3.7.

vstinner added a commit that referenced this pull request Jul 21, 2018
…H-8352)

Py_Main() can again be called after Py_Initialize(), as in Python
3.6. The new configuration is ignored, except of
_PyMainInterpreterConfig.argv which is used to update sys.argv.
(cherry picked from commit fb47bca)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
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.

None yet

7 participants