Changing optimisation level from a script
Hi all, When starting CPython from the command line you can pass the -O option to enable optimisations (eg `assert 0` won't raise an exception when -O is passed). But, AFAIK, there is no way to change the optimisation level after the interpreter has started up, ie there is no Python function call or variable that can change the optimisation. In MicroPython we want to be able to change the optimisation level from within a script because (on bare metal at least) there is no analog of passing options like -O. My idea would be to have a function like `sys.optimise(value)` that sets the optimisation level for all subsequent runs of the parser/compiler. For example: import sys import mymodule # no optimisations exec('assert 0') # will raise an exception sys.optimise(1) # enable optimisations import myothermodule # optimisations are enabled for this (unless it's already imported by mymodule) exec('assert 0') # will not raise an exception What do you think? Sorry if this has been discussed before! Cheers, Damien.
participants (11)
-
Andrew Svetlov
-
Brett Cannon
-
Damien George
-
Guido van Rossum
-
Ivan Levkivskyi
-
M.-A. Lemburg
-
MRAB
-
Nick Coghlan
-
Petr Viktorin
-
Steven D'Aprano
-
Victor Stinner