3.1 Selecting the functions to compile

With the following functions you can explicitely control what parts of your application get compiled.

bind( object, rec=10)
Tells Psyco that the given object should be compiled for faster execution.

If object is a Python function, bind modifies the function object in-place (specifically, its func_code attribute is changed). All future calls to the function will go through Psyco. Remember that in Python no behavior can depend on which reference to the function you use to make the call; in other words, after

g = f

calls to both f and g will go through Psyco.

The object argument can also be:

Note that compilation never actually starts before a function is first called.

All functions called by a compiled function are also compiled, as well as the functions called by these, and so on, up to some limit (by default 10) that you can specify as the optional second argument.

proxy( function-or-method, rec=10)
Makes a Psyco-enabled copy of object.

This function returns a new object, which is a copy of the function-or-method with the same behavior but going through Psyco. The function or method must be implemented in Python. The argument itself is not affected; if you call it, it will still be run by the regular interpreter.

Thus, "bind(f)" is similar to "f=proxy(f)", except that any reference to f that might previously have been taken (for example by a "from spam import *" statement) are unaffected in the second case.

unbind( object)
Cancels the action of bind.

Note that Psyco currently cannot release the memory occupied by the compilation of a function.

unproxy( proxy-object)
Reverse of proxy.

unproxy(proxy(f)) is a new function object equal to f. Calling it does no longer invoke Psyco.

cannotcompile( object)
Prevents the given function to be ever compiled by Psyco. object can also be a method object or directly a code object. Raises psyco.error if the object is already being compiled. Note that this does not prevent functions called by object to be compiled, if they are bound or proxied or if the profiler chooses to compile them.

setfilter( func or None)
Sets a global filter function: ``func(co)`` will be called once per code object co considered by Psyco. If it returns False, the code object will not be compiled. Note that ``func(co)`` will not be called if Psyco already started to compile the code object before you called setfilter, nor if the code object contains constructs that prevents Psyco from compiling it anyway. The return value of setfilter is the previous filter function or None.

The same function will never be compiled over and over again, so that you can freely mix calls to bind, proxy, unbind and unproxy and to the profile-based routines described in the next section.