[Pythonmac-SIG] Embedding Python in Cocoa

Michael Terry formido at gmail.com
Tue Dec 4 08:45:35 CET 2007


Sweet, thanks!

Michael

On 12/3/07, Andrew Trevorrow <andrew at trevorrow.com> wrote:
> Michael Terry wrote:
>
> > Suppose you had a Cocoa program that executed Python scripts
> > periodically. If global variables were set, they'd retain their values
> > between script runs. What would be the best approach to make this
> > happen?
> >
> > Call the C APIs? If so, do I just need to initialize a Python
> > interpreter when the program starts and not finalize it until the
> > program closes--or will it be more complicated than that?
>
> Yep, just call Py_Initialize once.  In fact, it's not a good idea
> to call Py_Initialize and Py_Finalize multiple times because they
> cause a memory leak of about 10K each time.  In our app we don't
> even bother calling Py_Finalize at the end because it causes a
> slight but annoying delay.
>
> If you want to see the way we do things then go to
> https://sourceforge.net/projects/golly/
> and either browse CVS or download the source code and look at
> wxpython.cpp.
>
> Andrew
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>


More information about the Pythonmac-SIG mailing list