[damned-lies] Handle broken pipe errors
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [damned-lies] Handle broken pipe errors
- Date: Tue, 17 Nov 2009 07:56:13 +0000 (UTC)
commit 55aa33d112e1219e620b89329f11a693b56ac57d
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Nov 17 08:39:02 2009 +0100
Handle broken pipe errors
For some long commands, if the requestor has closed before the command
terminates, the command may generate a 'Broken pipe' error. Catch it
and ignore.
stats/utils.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/stats/utils.py b/stats/utils.py
index 6a68df9..de0abfc 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -22,6 +22,7 @@
import sys, os, re, time
from itertools import islice
from subprocess import Popen, PIPE
+import errno
from django.utils.translation import ugettext_noop
from django.contrib.sites.models import Site
@@ -63,7 +64,11 @@ def run_shell_command(cmd, env=None, input_data=None, raise_on_error=False):
env = os.environ
pipe = Popen(cmd, shell=True, env=env, stdin=stdin, stdout=PIPE, stderr=PIPE)
if input_data:
- pipe.stdin.write(input_data)
+ try:
+ pipe.stdin.write(input_data)
+ except IOError, e:
+ if e.errno != errno.EPIPE:
+ raise
(output, errout) = pipe.communicate()
status = pipe.returncode
if settings.DEBUG: print >>sys.stderr, output + errout
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]