File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -238,7 +238,10 @@ def close(self, needs_lock: bool = True) -> None:
238238 with self ._optional_lock (needs_lock ):
239239 default = None
240240 file = self ._cache .pop (self ._key , default )
241- if file is not None :
241+ if needs_lock and self ._lock :
242+ with self ._lock :
243+ file .close ()
244+ else :
242245 file .close ()
243246
244247 def __del__ (self ) -> None :
@@ -396,7 +399,11 @@ def close(self, needs_lock: bool = True) -> None:
396399 del needs_lock # unused
397400 if not self ._closed :
398401 file = self ._get_unclosed_file ()
399- file .close ()
402+ if needs_lock and self ._lock :
403+ with self ._lock :
404+ file .close ()
405+ else :
406+ file .close ()
400407 self ._file = None
401408 # Remove all references to opener arguments, so they can be garbage
402409 # collected.
You can’t perform that action at this time.
0 commit comments