Skip to content

Commit e1398d8

Browse files
committed
Add dedicated decorator to ignore only the fork in thread deprecation warnings
1 parent 868ffd6 commit e1398d8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Lib/test/support/warnings_helper.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ def wrapper(self, *args, **kwargs):
6767
return wrapper
6868
return decorator
6969

70+
71+
def ignore_fork_in_thread_deprecation_warnings(test):
72+
"""Decorator to suppress the deprecation warnings related to running a fork within a thread.
73+
"""
74+
if inspect.iscoroutinefunction(test):
75+
@functools.wraps(test)
76+
async def async_wrapper(self, *args, **kwargs):
77+
with warnings.catch_warnings():
78+
warnings.filterwarnings('ignore',
79+
message=".*fork.*may lead to deadlocks in the child.*",
80+
category=DeprecationWarning)
81+
return await test(self, *args, **kwargs)
82+
return async_wrapper
83+
else:
84+
@functools.wraps(test)
85+
def wrapper(self, *args, **kwargs):
86+
with warnings.catch_warnings():
87+
warnings.filterwarnings('ignore',
88+
message=".*fork.*may lead to deadlocks in the child.*",
89+
category=DeprecationWarning)
90+
return test(self, *args, **kwargs)
91+
return wrapper
92+
7093

7194
class WarningsRecorder(object):
7295
"""Convenience wrapper for the warnings list returned on

0 commit comments

Comments
 (0)