Safe Psyco
David Mertz, Ph.D.
mertz at gnosis.cx
Fri Oct 11 17:02:25 EDT 2002
I wrote recently:
|Nonetheless, my article on Psyco recently appeared at:
| http://www-106.ibm.com/developerworks/linux/library/l-psyco.html
|...It makes me wonder if Python programmers shouldn't start trying to
|import Psyco fairly routinely (in try/except blocks that fail gracefully
|where Psyco is absent).
I mentioned routine use of Psyco in this note earlier today. I figured
I'd followup with more explicit description of what I mean. You could
stick the following at the top of your script:
try:
import psyco
from psyco.classes import *
except ImportError:
class _psyco:
def jit(self): pass
def bind(self, f): pass
def proxy(self, f): return f
psyco = _psyco()
This will be happy whether or not Psyco is installed on a given system.
Once this bit is at the top, you are free to scatter 'psyco.bind(func)',
'newfun = psyco.proxy(func)' and 'psyco.jit()' calls through the rest of
your script. Obviously, which calls you decide to use is still
determined by the same principles as in a regular Psyco program.
But the nice thing about this block is that nothing at all bad will
happen if a user doesn't have Psyco. All the calls will be dummies, and
no speedup will occur. But the program will still run in a
non-specializing way... as plain Python.
Yours, David...
--
Keeping medicines from the bloodstreams of the sick; food from the bellies of
the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.
More information about the Python-list
mailing list