Skip to content

Commit 5b19978

Browse files
committed
Hold lock while assigning self._module methods.
1 parent 9bd8875 commit 5b19978

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Lib/warnings.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,17 +504,17 @@ def __enter__(self):
504504
self._module._filters_mutated_lock_held()
505505
self._showwarning = self._module.showwarning
506506
self._showwarnmsg_impl = self._module._showwarnmsg_impl
507+
if self._record:
508+
log = []
509+
self._module._showwarnmsg_impl = log.append
510+
# Reset showwarning() to the default implementation to make sure
511+
# that _showwarnmsg() calls _showwarnmsg_impl()
512+
self._module.showwarning = self._module._showwarning_orig
513+
else:
514+
log = None
507515
if self._filter is not None:
508516
simplefilter(*self._filter)
509-
if self._record:
510-
log = []
511-
self._module._showwarnmsg_impl = log.append
512-
# Reset showwarning() to the default implementation to make sure
513-
# that _showwarnmsg() calls _showwarnmsg_impl()
514-
self._module.showwarning = self._module._showwarning_orig
515-
return log
516-
else:
517-
return None
517+
return log
518518

519519
def __exit__(self, *exc_info):
520520
if not self._entered:

0 commit comments

Comments
 (0)