[pypy-commit] pypy resource_warning: (florin, antocuni) IN-PROGRESS: Attach and show the creation traceback. Test fails and we don't know why
florinpapa
pypy.commits at gmail.com
Thu Apr 7 04:29:40 EDT 2016
Author: florinpapa
Branch: resource_warning
Changeset: r83558:980ad9d11a2a
Date: 2016-04-07 11:28 +0300
http://bitbucket.org/pypy/pypy/changeset/980ad9d11a2a/
Log: (florin, antocuni) IN-PROGRESS: Attach and show the creation
traceback. Test fails and we don't know why
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1740,14 +1740,24 @@
_warnings.warn(msg, warningcls, stacklevel=stacklevel)
""")
- def resource_warning(self, msg):
- w_msg = self.wrap(msg)
- self.appexec([w_msg],
- """(msg):
+ def resource_warning(self, w_msg, w_tb):
+ self.appexec([w_msg, w_tb],
+ """(msg, tb):
import sys
print >> sys.stderr, msg
+ if tb:
+ print >> sys.stderr, "Created at (most recent call last):"
+ print >> sys.stderr, tb
""")
+ def format_traceback(self):
+ self.appexec([],
+ """():
+ import traceback
+ return "".join(traceback.format_stack())
+ """)
+
+
class AppExecCache(SpaceCache):
def build(cache, source):
""" NOT_RPYTHON """
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -38,11 +38,14 @@
errors = None
fd = -1
cffi_fileobj = None # pypy/module/_cffi_backend
+ w_tb = None # String representation of the traceback at creation time
newlines = 0 # Updated when the stream is closed
def __init__(self, space):
self.space = space
+ if self.space.sys.resource_warning_enabled:
+ self.w_tb = self.space.format_traceback()
def __del__(self):
# assume that the file and stream objects are only visible in the
@@ -57,7 +60,8 @@
if self.space.sys.resource_warning_enabled:
w_repr = self.space.repr(self)
str_repr = self.space.str_w(w_repr)
- self.space.resource_warning("WARNING: unclosed file: " + str_repr)
+ w_msg = self.space.wrap("WARNING: unclosed file:" + str_repr)
+ self.space.resource_warning(w_msg, self.w_tb)
#
try:
self.direct_close()
diff --git a/pypy/module/_file/test/test_file.py b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -275,7 +275,14 @@
assert fn() == ""
sys.pypy_set_resource_warning(True)
msg = fn()
+
+ #f1 = open("/tmp/test", "w+")
+ #import pdb; pdb.set_trace()
+ print msg
+ #close(f1)
+
assert msg.startswith("WARNING: unclosed file: <open file ")
+ assert "Created at (most recent call last):" in msg
finally:
sys.pypy_set_resource_warning(False)
More information about the pypy-commit
mailing list