homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Would like Py_Initialize to play friendly with host app
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dangermouseb, eric.snow, isoschiz, ncoghlan, pconnell, pitrou, vstinner, ynkdir
Priority: normal Keywords:

Created on 2011年12月05日 15:36 by dangermouseb, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (5)
msg148875 - (view) Author: (dangermouseb) Date: 2011年12月05日 15:36
I'm building a dll add-in (on Windows) in which I want to use the installed version of Python, not provide my own installation. When py_initialize fails it appears to call exit(). This doesn't seem very friendly behaviour for an embeddable scripting language as the host application is terminated (out of my control).
So my request is that either py_initialize is changed to return a code indicating failure or sucess or another function is added to th api to test if the installation is good or not. That way I can report to the user that there is a problem in the python installation rather than apparently crashing the host app.
Currently the only strategy I've thought of to get around this is to fork a seperate process, and inspect it after a delay to see if it is running (indicating that py_initialize hasn't failed), terminate the new process and then call py_initialize in the host application process.
This has been raised before but only in terms of consistency with the documentation, not about if a embeddable scripting engine should terminate the hosting process without regard to that host.
Many thanks,
David
msg148881 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011年12月05日 18:06
If we add a (yet another) variant of Py_Initialize, I would suggest we make it extensible by passing it a struct of arguments (so that the struct can be augmented without breaking compatibility).
msg223829 - (view) Author: Yukihiro Nakadaira (ynkdir) Date: 2014年07月24日 11:45
This problem easily happen when there is no python installation and there is standalone python application compiled with py2exe or cx_Freeze (e.g. Mercurial). Such application have pythonXX.dll in its directory. But its python library can not be loaded normally. So an application, which loads pythonXX.dll to check if python is available and uses it if possible, is terminated when loading python.
Vim uses python as embedding scripting language. Vim loads pythonXX.dll when :python command is used. And this problem is reported occasionally.
msg223904 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2014年07月24日 22:28
Changing this isn't really feasible with the current design of the initialisation code - we call Py_FatalError in various places because we don't have the infrastructure set up to do anything else.
PEP 432 should help (and the basic design there still seems sound), since we'll have the core interpreter up and running much earlier, and hence be able to make use of the non-fatal exception machinery. However, it would still mean carefully reviewing everywhere we call Py_FatalError and ensuring there's an error returning path back up to the embedding application.
Unfortunately, I don't know when I'm going to find time to get back to that, and the startup process is sufficiently arcane that it wouldn't be a quick process for someone else to come up to speed on the current state of the draft implementation :(
msg343632 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019年05月27日 14:45
> I'm building a dll add-in (on Windows) in which I want to use the installed version of Python, not provide my own installation. When py_initialize fails it appears to call exit(). (...)
This issue has been fixed by the PEP 587 in bpo-36763: Py_InitializeFromConfig() now returns a PyStatus structure which is a success, error message or an exit code. The caller can decide how to handle it.
History
Date User Action Args
2022年04月11日 14:57:24adminsetgithub: 57742
2019年05月27日 14:45:29vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg343632

resolution: fixed
stage: resolved
2014年07月24日 22:28:54ncoghlansetmessages: + msg223904
2014年07月24日 21:13:04pitrousetnosy: + ncoghlan
2014年07月24日 11:45:35ynkdirsetnosy: + ynkdir
messages: + msg223829
2013年04月23日 21:37:53isoschizsetnosy: + pconnell, isoschiz
2011年12月05日 20:12:08eric.snowsetnosy: + eric.snow
2011年12月05日 18:06:07pitrousetversions: + Python 3.3, - Python 2.7, Python 3.4
nosy: + pitrou

messages: + msg148881

components: + Interpreter Core, - None
2011年12月05日 15:36:34dangermousebcreate

AltStyle によって変換されたページ (->オリジナル) /