FAQ
Hi,

When embedding Python in C++, is there anyway to initialize the
interpreter so that it runs in optimized mode, equivalent to
specifying the -O flag when running the interpreter from the command
line?

Thanks,
John

Search Discussions

  • Fredrik Lundh at Apr 16, 2004 at 6:46 pm

    JT wrote:

    When embedding Python in C++, is there anyway to initialize the
    interpreter so that it runs in optimized mode, equivalent to
    specifying the -O flag when running the interpreter from the command
    line?
    here's one way to do it:

    putenv("PYTHONOPTIMIZE=yes");
    ... initialize interpreter as usual ...

    </F>
  • Rick Ratzel at Apr 16, 2004 at 10:51 pm

    JT wrote:
    Hi,

    When embedding Python in C++, is there anyway to initialize the
    interpreter so that it runs in optimized mode, equivalent to
    specifying the -O flag when running the interpreter from the command
    line?

    Thanks,
    John
    set Py_OptimizeFlag to 1 for -O, and 2 for -OO. Do this prior to
    calling Py_Initialize();

    You can also improve your startup time by setting
    Py_NoSiteFlag = 1...assuming you don't need to load site.py

    for example:

    extern int Py_OptimizeFlag;
    extern int Py_NoSiteFlag;
    ...
    if( !Py_IsInitialized() ) {
    Py_OptimizeFlag = 2;
    Py_NoSiteFlag = 1;
    Py_Initialize();
    }
  • John at Apr 17, 2004 at 12:28 am
    "Rick Ratzel" <rick.ratzel at magma-da.com> wrote in message
    news:4080635b$0$46515$39cecf19 at news.twtelecom.net...
    set Py_OptimizeFlag to 1 for -O, and 2 for -OO. Do this prior to
    calling Py_Initialize();

    You can also improve your startup time by setting
    Py_NoSiteFlag = 1...assuming you don't need to load site.py

    for example:

    extern int Py_OptimizeFlag;
    extern int Py_NoSiteFlag;
    ...
    if( !Py_IsInitialized() ) {
    Py_OptimizeFlag = 2;
    Py_NoSiteFlag = 1;
    Py_Initialize();
    }
    I was viewing this thread from Google groups and didn't see your response
    before I replied. This is exactly what I was looking for...thanks! Out of
    curiosity, what does the -OO flag do on top of the normal optimizations?
  • Harald Massa at Apr 17, 2004 at 7:57 am

    I was viewing this thread from Google groups and didn't see your
    response before I replied. This is exactly what I was looking
    for...thanks! Out of curiosity, what does the -OO flag do on top of
    the normal optimizations?
    Strip """
    Doc-Strings
    """

    Harald
  • JT at Apr 17, 2004 at 12:13 am
    "Fredrik Lundh" <fredrik at pythonware.com> wrote in message
    here's one way to do it:

    putenv("PYTHONOPTIMIZE=yes");
    ... initialize interpreter as usual ...

    </F>
    Thanks for response! I'll try this solution. Does anyone know of any
    way to do this directly through the Python C/C++ API, such as by
    modifying a variable representing the state, interpreter or compiler,
    or by calling a specific method?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 16, '04 at 6:34p
activeApr 17, '04 at 7:57a
posts6
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase