Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner 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

@hroncok
Copy link
Contributor

hroncok commented Jul 2, 2018

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

@hroncok
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'

@ncoghlan
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.

@hroncok
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 😄

@ncoghlan
Copy link
Contributor

ncoghlan commented Jul 4, 2018

I just meant this PR :)

@ilovezfs
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.

vstinner added 3 commits July 20, 2018 15:13
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.
@hroncok
Copy link
Contributor

hroncok commented Jul 20, 2018

this fixes the fontforge issue

Copy link
Contributor

@ncoghlan 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 vstinner merged commit fb47bca into python:master Jul 20, 2018
@vstinner vstinner deleted the init_pymain branch July 20, 2018 15:34
@miss-islington
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>
@bedevere-bot
Copy link

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

@vstinner
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.

7 participants