You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/ql/src/Resources/FileNotAlwaysClosed.qhelp
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,16 @@
4
4
<qhelp>
5
5
6
6
<overview>
7
-
<p>When a file is opened, it should always be closed. Failure to close files could result in loss of data or resource leaks.</p>
8
-
7
+
<p>When a file is opened, it should always be closed.
8
+
</p>
9
+
<p>A file opened for writing that is not closed when the application exits may result in data loss, where not all of the data written may be saved to the file.
10
+
A file opened for reading or writing that is not closed may also use up file descriptors, which is a resource leak that in long running applications could lead to a failure to open additional files.
11
+
</p>
9
12
</overview>
10
13
<recommendation>
11
14
12
15
<p>Ensure that opened files are always closed, including when an exception could be raised.
13
-
The best practice is to use a <code>with</code> statement to automatically clean up resources.
16
+
The best practice is often to use a <code>with</code> statement to automatically clean up resources.
14
17
Otherwise, ensure that <code>.close()</code> is called in a <code>try...except</code> or <code>try...finally</code>
0 commit comments