Closing a Resource More Than Once

An interface should state whether repeat cleanup succeeds safely, reports an already-closed state, or is outside its supported use.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace ownership
  2. Verify repeated use separately

Trace ownership

One caller can open a reader and pass it to a function that only borrows it. If that function closes it, the owner may be unable to use it again. See input ownership.

Verify repeated use separately

Test one close and a second close according to the resource's explicit contract. A helper retrying cleanup should know whether it is a safe state transition.[1]

References

  1. Python Software Foundation, Python Tutorial: Errors and Exceptions ↩