looking for command-pipe performance advice

Erno Kuusela erno-news at erno.iki.fi
Sun Apr 8 16:04:56 EDT 2001


In article <mailman.986514369.6320.python-list at python.org>,
jason-dated-af27661e5bfe243d at mastaler.com writes:

| Can anyone suggest a more efficient, and/or higher performance method
| of reading in a mail message as standard input, and then feeding the
| message to a command pipe (qmail in my case).

| I do need to examine the mail headers, but don't need to look at the
| message body at all.

1) rfc822.Message is not blindingly fast. if you only need to
glance at the headers, you can probably make things go faster
by doing it without rfc822.Message.

2) os.popen() spawns a shell for the command, so what really gets
executed is /bin/sh -c "/var/qmail/bin/qmail-inject".  you can do
better by doing the pipe/fork/exec yourself (or use the undocumented
feature of the popen2 module, it'll avoid sh if you pass a list
instead of a string).

  -- erno



More information about the Python-list mailing list