diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 21:57:19 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 21:57:19 (GMT) |
commit | a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a (patch) | |
tree | 15831806e742293faad56b1b3c880d1293cf2a4c /Lib/asyncore.py | |
parent | c3bc856f426d8c182b4ecbdf584717e27389c505 (diff) | |
parent | 4d4c69dc35154a9c21fed1b6b4088e741fbc6ae6 (diff) | |
download | cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.zip cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.tar.gz cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.tar.bz2 |
(Merge 3.4) Issue #11453: asyncore: emit a ResourceWarning when an unclosed
file_wrapper object is destroyed. The destructor now closes the file if needed.
The close() method can now be called twice: the second call does nothing.
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r-- | Lib/asyncore.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 37efa9b..b2ee278 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -600,6 +600,11 @@ if os.name == 'posix': def __init__(self, fd): self.fd = os.dup(fd) + def __del__(self): + if self.fd >= 0: + warnings.warn("unclosed file %r" % self, ResourceWarning) + self.close() + def recv(self, *args): return os.read(self.fd, *args) @@ -618,7 +623,10 @@ if os.name == 'posix': write = send def close(self): + if self.fd < 0: + return os.close(self.fd) + self.fd = -1 def fileno(self): return self.fd |