[Pythonmac-SIG] Python dieing outside project builder

Matthew Smith mps@utas.edu.au
Fri, 14 Jun 2002 09:13:12 +1000


Hello,

Thanks for the help!

I'm calling:

Py_SetProgramName("My App");
Py_Initialize();

I then make python aware of some functions in the app.

Then:

VBALLOW_PYTHON = !PyRun_SimpleString("execfile(\"autoexec.py\")\n");

if (!VBALLOW_PYTHON)
   printf("autoexec didn't execute!\n");

Where VBALLOW_PYTHON is a bool.

I'll give printing the working directory, or setting the Py_VerboseFlag to
1, though my app seems to pick up other files in the same directory ok...

Also, I'm quite the python novice, but it seems that I am doing a simaler
thing to yours, Alex...

Thanks again,

Matt

> Mattew,
> 
> I don't think the current folder should have any importance with the
> frameworks since the paths are hard coded at ./configure time. I'm
> developing from CodeWarrior BTW.
> 
> Here is what I do:
> 
> #elif TARGET_RT_MAC_CFM
>   console_output_state = 1;
>   
>   PyMac_SetConsoleHandler(PyMac_DummyReadHandler, PyMac_DummyWriteHandler,
>       PyMac_DummyWriteHandler);
>   
>   PyMacSchedParams scp;
>   
>   PyMac_GetSchedParams(&scp);
>   scp.process_events = 0;
>   PyMac_SetSchedParams(&scp);
> 
>   Py_SetProgramName("maccvs");
> #elif TARGET_RT_MAC_MACHO
>   Py_SetProgramName("maccvsX");
>   Py_Initialize();
> #else
> 
> I have also some code which makes sure that prior to that the current
> resource fork is the application one which has the 'Popt' resource inside,
> but I suspect it is used only with PythonCFM's Py_MacInitialize.
> 
> Some more code:
> 
>   PyEval_InitThreads();
>   m_mainInterpreter = PyThreadState_Swap(NULL);
> 
>   PyThreadState *OLD = PyThreadState_Swap(m_mainInterpreter);
> 
>    PyObject *m = Py_InitModule4("_cvsgui", &gAllMethods[0],
>       "The cvsgui glue functions", (PyObject*)NULL,PYTHON_API_VERSION);
> 
>   ....
> 
>  PyThreadState_Swap(OLD );
> 
> 
> 
> resource 'Popt' (PYTHONOPTIONSOVERRIDE_ID, "Options") {
>   POPT_VERSION_CURRENT,
>   noInspect,
>   noVerbose,
>   noOptimize,
>   noUnbuffered,
>   noDebugParser,
>   unused_0,
>   noCloseOutput,
>   interactiveOptions,
>   argcArgv,
>   newStandardExceptions,
>   sitePython,
>   navService,
>   delayConsole,
>   noDivisionWarning,
>   unixNewlines,
> };
> 
> Hope it helps,
> Alex.
> 
> 
>> 
>> On donderdag, juni 13, 2002, at 03:36 , Matthew Smith wrote:
>> 
>>> Hello,
>>> 
>>> I'm linking to the python framework in an app I'm working on,
>>> the app needs
>>> to run a python script at start-up.
>>> 
>>> If I run the app from inside project builder everything works
>>> and the return
>>> value for executing the script is fine.
>>> 
>>> If the program is launched outside project builder (eg
>>> double-clicking on it
>>> in the finder), the script doesn't run and the return value
>>> gives an error.
>>> 
>>> The script I am running is with the .app file in the build directory...
>>> 
>>> Any ideas?
>> 
>> Just a wild guess: when you double-click you could have a
>> different working directory than when you run from Project
>> Builder. You could put some debug output in your embedding
>> application (for instance print the working directory, or set
>> the Py_VerboseFlag to 1 before calling Python), and the output
>> will appear in the console window
>> (Applications->Utilities->Console).
>> 
>> I'm also not 100% sure which Python initialize routine you need
>> to call if your Python scripts want access to Carbon methods. I
>> think Py_Initialize() may be good enough, but it could be that
>> you have to use PyMac_Initialize() (as in MacPython). Or maybe
>> you even need something completely different (i.e.
>> Py_Initialize() plus some of the stuff in PyMac_Initialize().
>> 
>> Maybe someone else has already experimented with embedding
>> MachoPython and has information to share?
>> --
>> - Jack Jansen        <Jack.Jansen@oratrix.com>
>> http://www.cwi.nl/~jack -
>> - If I can't dance I don't want to be part of your revolution --
>> Emma Goldman -
>> 
>> 
>> 
>> _______________________________________________
>> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>> http://mail.python.org/mailman/listinfo/pythonmac-sig
>> 
> 

-- 
 
"Many that live deserve death. And some die that deserve life. Can you give
that to them? Then be not too eager to deal out death in the name of
justice, fearing for your own safety. Even the wise cannot see all ends."

JRR Tolkien, The Two Towers - The Lord of the Rings.