SourceForge logo
SourceForge logo
Menu

[matplotlib-devel] Add some caching to texmanager.py?

From: Fernando P. <Fer...@co...> - 2005年06月21日 19:52:38
Hi all,
I just had this crash in mpl:
/usr/lib/python2.3/site-packages/matplotlib/texmanager.py in 
get_dvipng_version(self)
 299 def get_dvipng_version(self):
 300 if self.dvipngVersion is not None: return 
self.dvipngVersion
--> 301 sin, sout = os.popen2('dvipng --version')
 302 for line in sout.readlines():
 303 if line.startswith('dvipng '):
/usr/lib/python2.3/os.py in popen2(cmd, mode, bufsize)
 614 def popen2(cmd, mode="t", bufsize=-1):
 615 import popen2
--> 616 stdout, stdin = popen2.popen2(cmd, bufsize)
 617 return stdin, stdout
 618 __all__.append("popen2")
/usr/lib/python2.3/popen2.py in popen2(cmd, bufsize, mode)
 145 specified, it sets the buffer size for the I/O pipes. 
The file objects
 146 (child_stdout, child_stdin) are returned."""
--> 147 inst = Popen3(cmd, False, bufsize)
 148 return inst.fromchild, inst.tochild
 149
/usr/lib/python2.3/popen2.py in __init__(self, cmd, capturestderr, bufsize)
 40 if capturestderr:
 41 errout, errin = os.pipe()
---> 42 self.pid = os.fork()
 43 if self.pid == 0:
 44 # Child
OSError: [Errno 12] Cannot allocate memory
This was in a long-running session with very large memory allocations, 
but it dawned on me that get_dvipng_version(self) should cache its 
return value. There's no point in forcing a popen() call every single 
time, is there?
I don't know the texmanager code, so I don't want to touch it myself. 
But if the idea is OK, a simple property tag is enough to cache:
In [3]: def cached():
 ...: try:
 ...: return cached.cachedvalue
 ...: except AttributeError:
 ...: cached.cachedvalue=42
 ...: return cached.cachedvalue
 ...:
In [4]: cached()
Out[4]: 42
I also just saw pylab crash when a user was trying to run with $PWD 
being something he didn't have write access to. Are there any checks in 
the code to fall back to /tmp or something sensible if texmanager can't 
write the temp files it needs? Sorry for not giving a traceback, but I 
only saw this on someone else's screen while helping them, and for some 
odd reason it's not happening on my box.
Cheers,
f

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /