BIND 10 #1828: Python tests print warnings about unclosed file handles / sockets
BIND 10 Development
do-not-reply at isc.org
Thu Jun 7 07:20:10 UTC 2012
#1828: Python tests print warnings about unclosed file handles / sockets
-------------------------------------+-------------------------------------
Reporter: muks | Owner: jinmei
Type: | Status: reviewing
defect | Milestone:
Priority: | Sprint-20120612
medium | Resolution:
Component: | Sensitive: 0
Unclassified | Sub-Project: DNS
Keywords: | Estimated Difficulty: 4
Defect Severity: N/A | Total Hours: 0
Feature Depending on Ticket: |
Add Hours to Ticket: 0 |
Internal?: 0 |
-------------------------------------+-------------------------------------
Changes (by muks):
* owner: muks => jinmei
Comment:
Replying to [comment:13 jinmei]:
> I'm afraid I don't understand this...
>
> - In "the object goes out of scope" case, the underlying FD should be
> immediately closed (with the warning), so it basically shouldn't
> cause the descriptor exhaustion (as long as the scope is
> sufficiently small), right?
> - "these don't happen in a recu(r)sive style..." is not clear to me.
> Are these the points that actually cause the FD exhaustion?
None of the cases that print these warnings should cause fd exhaustion
with CPython.
> But since it's not so obvious why we need to do the seemingly
> redundant close(), I'd suggest updating the coding guideline page
> http://bind10.isc.org/wiki/CodingGuidelines#PythonStyle
> to explain this issue and what we generally should do in our code. I
> also suggest raising this at the bind10-dev list so other developers
> can recognize it.
http://bind10.isc.org/wiki/CodingGuidelines#Closeallfileandsocketobjects
I have mailed bind10-dev too.
> Regarding the branch itself...
>
> - (repeating my original comment) I'd suggest using 'file' or
> at least something different from 'fd' to represent file object.
> - it would probably be even better to use the `with` idiom so the code
> is more exception safe in terms of the timing of close(). That is,
> instead of
> {{{#!python
> file = open(self.pid_file, "w")
> file.write('dummy data\n')
> file.close()
> }}}
> do this:
> {{{#!python
> # or in this simple case it could be a one-liner.
> with open(self.pid_file, "w") as file:
> file.write('dummy data\n')
> }}}
This still doesn't call `.close()`.
--
Ticket URL: <http://bind10.isc.org/ticket/1828#comment:15>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development
More information about the bind10-tickets
mailing list