[pypy-commit] pypy default: improve subprocess error handling
pjenvey
noreply at buildbot.pypy.org
Thu Oct 13 02:03:42 CEST 2011
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r48012:c041e29173a9
Date: 2011-10-12 17:02 -0700
http://bitbucket.org/pypy/pypy/changeset/c041e29173a9/
Log: improve subprocess error handling
diff --git a/pypy/jit/backend/x86/tool/viewcode.py b/pypy/jit/backend/x86/tool/viewcode.py
--- a/pypy/jit/backend/x86/tool/viewcode.py
+++ b/pypy/jit/backend/x86/tool/viewcode.py
@@ -9,7 +9,12 @@
"""
import autopath
-import operator, sys, os, re, py, new
+import new
+import operator
+import py
+import re
+import sys
+import subprocess
from bisect import bisect_left
# don't use pypy.tool.udir here to avoid removing old usessions which
@@ -44,14 +49,16 @@
f = open(tmpfile, 'wb')
f.write(data)
f.close()
- g = os.popen(objdump % {
+ p = subprocess.Popen(objdump % {
'file': tmpfile,
'origin': originaddr,
'backend': objdump_backend_option[backend_name],
- }, 'r')
- result = g.readlines()
- g.close()
- lines = result[6:] # drop some objdump cruft
+ }, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ assert not p.returncode, ('Encountered an error running objdump: %s' %
+ stderr)
+ # drop some objdump cruft
+ lines = stdout.splitlines()[6:]
return format_code_dump_with_labels(originaddr, lines, label_list)
def format_code_dump_with_labels(originaddr, lines, label_list):
@@ -85,8 +92,12 @@
#
print 'loading symbols from %s...' % (filename,)
symbols = {}
- g = os.popen(symbollister % filename, "r")
- for line in g:
+ p = subprocess.Popen(symbollister % filename, shell=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ assert not p.returncode, ('Encountered an error running nm: %s' %
+ stderr)
+ for line in stdout.splitlines():
match = re_symbolentry.match(line)
if match:
addr = long(match.group(1), 16)
@@ -94,7 +105,6 @@
if name.startswith('pypy_g_'):
name = '\xb7' + name[7:]
symbols[addr] = name
- g.close()
print '%d symbols found' % (len(symbols),)
return symbols
More information about the pypy-commit
mailing list