4
4
import sys
5
5
import unittest
6
6
import warnings
7
- import functools
8
7
from unittest import mock
9
8
10
9
import asyncio
31
30
'sys.stdout.buffer.write(data)' ))]
32
31
33
32
34
- @functools .cache
35
- def _has_pidfd_support ():
36
- if not hasattr (os , 'pidfd_open' ):
37
- return False
38
-
39
- try :
40
- os .close (os .pidfd_open (os .getpid ()))
41
- except OSError :
42
- return False
43
-
44
- return True
45
-
46
-
47
33
def tearDownModule ():
48
34
asyncio .set_event_loop_policy (None )
49
35
@@ -688,7 +674,7 @@ def setUp(self):
688
674
self .loop = policy .new_event_loop ()
689
675
self .set_event_loop (self .loop )
690
676
691
- watcher = self .Watcher ()
677
+ watcher = self ._get_watcher ()
692
678
watcher .attach_loop (self .loop )
693
679
policy .set_child_watcher (watcher )
694
680
@@ -703,32 +689,38 @@ def tearDown(self):
703
689
class SubprocessThreadedWatcherTests (SubprocessWatcherMixin ,
704
690
test_utils .TestCase ):
705
691
706
- Watcher = unix_events .ThreadedChildWatcher
707
-
708
- @unittest .skip ("bpo-38323: MultiLoopChildWatcher has a race condition \
709
- and these tests can hang the test suite" )
710
- class SubprocessMultiLoopWatcherTests (SubprocessWatcherMixin ,
711
- test_utils .TestCase ):
712
-
713
- Watcher = unix_events .MultiLoopChildWatcher
692
+ def _get_watcher (self ):
693
+ return unix_events .ThreadedChildWatcher ()
714
694
715
695
class SubprocessSafeWatcherTests (SubprocessWatcherMixin ,
716
696
test_utils .TestCase ):
717
697
718
- Watcher = unix_events .SafeChildWatcher
698
+ def _get_watcher (self ):
699
+ with self .assertWarns (DeprecationWarning ):
700
+ return unix_events .SafeChildWatcher ()
701
+
702
+ class MultiLoopChildWatcherTests (test_utils .TestCase ):
703
+
704
+ def test_warns (self ):
705
+ with self .assertWarns (DeprecationWarning ):
706
+ unix_events .MultiLoopChildWatcher ()
719
707
720
708
class SubprocessFastWatcherTests (SubprocessWatcherMixin ,
721
709
test_utils .TestCase ):
722
710
723
- Watcher = unix_events .FastChildWatcher
711
+ def _get_watcher (self ):
712
+ with self .assertWarns (DeprecationWarning ):
713
+ return unix_events .FastChildWatcher ()
724
714
725
715
@unittest .skipUnless (
726
- _has_pidfd_support (),
716
+ unix_events . can_use_pidfd (),
727
717
"operating system does not support pidfds" ,
728
718
)
729
719
class SubprocessPidfdWatcherTests (SubprocessWatcherMixin ,
730
720
test_utils .TestCase ):
731
- Watcher = unix_events .PidfdChildWatcher
721
+
722
+ def _get_watcher (self ):
723
+ return unix_events .PidfdChildWatcher ()
732
724
733
725
734
726
class GenericWatcherTests (test_utils .TestCase ):
@@ -758,7 +750,7 @@ async def execute():
758
750
759
751
760
752
@unittest .skipUnless (
761
- _has_pidfd_support (),
753
+ unix_events . can_use_pidfd (),
762
754
"operating system does not support pidfds" ,
763
755
)
764
756
def test_create_subprocess_with_pidfd (self ):
0 commit comments