[Zope3-Users] problems using os.popen2 in a heavily used utility

Shaar Gabriel gabi at shaargiora.co.il
Tue Jan 30 15:57:09 EST 2007


Hi.
i have a utility that generates thumbnails for objects that can be displayed 
as an image (faxes).

the part that generates the thumbnail :

	def generate_thumbnail(self, data):
		"""Return a smaller view of the data stream"""

		# if data stream is a djvu file, convert it to ps before thumbnailing.
		magic = getUtility(IFileMagic)
		mimetype = magic.getMimeType(data)
		if mimetype == "image/x.djvu":
			(stdin, stdout) = os.popen2("djvups - -")
			stdin.write(data)
			stdin.close()
			data = stdout.read()
			stdout.close()
		# Explenation of convert command line attributes :
		# -resize 150 : resize, while keeping aspect ratio, to a width of 150 pixels
		# -[1] : input file in stdin (-)  to extract only frame 1: -[1]).
		#        format detected automatically from data stream
		# png:- : output file on stdout (-) in png (png:) format
		(stdin, stdout) = os.popen2("convert -quiet -resize 150 - png:-")
		stdin.write(data)
		stdin.close()
		thumbnail = stdout.read()
		stdout.close()
		return thumbnail

this utility is used by a view that displays a grid of a few thumbnails.
when the view is loaded, several thumbnails are generated at once. (calls from 
the <img> tags to an /@@thumbnail view on the obect)
some thumbnail make it through (very few), the rest fail with :

2007-01-30T21:54:06 ERROR SiteError 
http://moobox:8080/2007/inbox/000005512/@@thumbnail
Traceback (most recent call last):
  File "/usr/lib/zope-3.3.0/lib/python/zope/publisher/publish.py", line 133, 
in publish
    result = publication.callObject(request, obj)
  
File "/usr/lib/zope-3.3.0/lib/python/zope/app/publication/zopepublication.py", 
line 161, in callObject
    return mapply(ob, request.getPositionalArguments(), request)
  File "/usr/lib/zope-3.3.0/lib/python/zope/publisher/publish.py", line 108, 
in mapply
    return debug_call(obj, args)
   - __traceback_info__: <bound method ThumbnailView.__call__ of 
<zope.app.publisher.browser.viewmeta.ThumbnailView object at 0xb4f1c20c>>
  File "/usr/lib/zope-3.3.0/lib/python/zope/publisher/publish.py", line 114, 
in debug_call
    return obj(*args)
  File "/var/lib/zope/office/lib/python/base/visual/browser.py", line 59, in 
__call__
    tf.write(self.data)
  File "/var/lib/zope/office/lib/python/base/thumbnail/browser/thumbnail.py", 
line 41, in data
    return getAdapter(self.context, IVisual, name="thumbnail").data
  File "/var/lib/zope/office/lib/python/base/thumbnail/thumbnail.py", line 21, 
in data
    thumbnail = tg.get_thumbnail(self.context)
  File "/var/lib/zope/office/lib/python/base/thumbnail/utility.py", line 80, 
in get_thumbnail
    thumb.image = StringIO(
  File "/var/lib/zope/office/lib/python/base/thumbnail/utility.py", line 67, 
in generate_thumbnail
    thumbnail = stdout.read()
IOError: [Errno 4] Interrupted system call


i read somewhere that os.popen2 is not friendly towards twisted framework, and 
that twisted.internet.reactor.spawnProcess or 
twisted.internet.process.Process should be used.
i can't undersnad what format the parameter childfds should look like when 
calling those. could somebody show me the equivalent of (stdin, stdout) = 
os.popen2(....) ?



More information about the Zope3-users mailing list