+
    Bi              	          ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHt ^ RIHtHtHtHt ^ RIHtHt  ^ RIt ! R R]P4                  4      t]P8                  ! ]
P:                  R8H  R4       ! R	 R
]P4                  4      4       t]P>                  ! ]
P:                  R8H  R4       ! R R]P4                  4      4       t  ! R R]P4                  4      t!]P8                  ! ]
P:                  R8H  R4       ! R R]P4                  4      4       t"]P>                  ! ]#! ]R4      R4       ! R R]P4                  4      4       t$]P8                  ! ]
P:                  R8H  R4      ]P>                  ! ]#! ]R4      R4      ]PJ                  ! 4       ]P>                  ! ]#! ]R4      R4       ! R R]P4                  4      4       4       4       4       t&]P8                  ! ]
P:                  R8H  R4      ]P>                  ! ]#! ]R4      ;'       d
    ]#! ]R4      R4       ! R R ]P4                  4      4       4       t' ! R! R"]P4                  4      t( ! R# R$]P4                  4      t) ! R% R&]P4                  4      t* ! R' R(]P4                  4      t+R) t,]-R*8X  d   ]P\                  ! 4        R# R#   ] d    Rt ELoi ; i)+    N)support)is_appleis_apple_mobile	os_helperthreading_helper)assert_python_okspawn_pythonc                   ,   a  ] tR t^t o R tR tRtV tR# )GenericTestsc                N   \        \        4       EF  p\        \        V4      pVR9   d#   V P                  V\        P                  4       K=  VR9   d#   V P                  V\        P
                  4       Kf  VP                  R4      '       d:   VP                  R4      '       g#   V P                  V\        P                  4       K  VP                  R4      '       g   K  V P                  V\        P                  4       V P                  \        P                  R4       EK  	  \        P                  ! \        P                  RRR \        R7      p\        P                  ! V\        P                  4       \        P                  ! \        P                  R	RR
 \        R7      p\        P                  ! V\        P                  4       \        \        RR4      pVeG   \        P                  ! \        P                  RRR \        R7      p\        P                  ! We4       R# R# )SIG_DFLSIGSIG_CTRL_win32Signalssignalc                     V P                  4       ;'       d8    V P                  R 4      ;'       d    V P                  R4      '       * ;'       g    V P                  R4      # )r   r   r   )isupper
startswithnames   &'/usr/lib/python3.14/test/test_signal.py<lambda>)GenericTests.test_enums.<locals>.<lambda>+   sR    LLN Q Q/OO8O4O0 0w/0    )sourceHandlersc                     V R9   # )r   )r   SIG_IGN r   s   &r   r   r   5   s
    T%;;r   SigmasksNc                     V R9   # )	SIG_BLOCK)r$   SIG_UNBLOCKSIG_SETMASKr!   r   s   &r   r   r   >   s
    )T!Tr   >   r   r    >   r$   r&   r%   )dirr   getattrassertIsInstancer   r"   r   r   assertEqualsysplatformenum_old_convert_IntEnum_test_simple_enum)selfr   sigCheckedSignalsCheckedHandlersr"   CheckedSigmaskss   &      r   
test_enumsGenericTests.test_enums   s|   KD&$'C--%%c6??;DD%%c6??;''0G0G%%c6>>:))%%c6>>:  w7   ++i0  	~v~~>,,j(;
 	@6:t4"00LL*hT!O
 ""?=  r   c                   \        \        4       Fk  p\        \        V4      p\        P                  ! V4      '       g   K1  \        P
                  ! V4      '       d   KO  V P                  VP                  R 4       Km  	  R# )r   N)r'   r   r(   inspect	isroutine	isbuiltinr*   
__module__)r1   r   values   &  r   test_functions_module_attr'GenericTests.test_functions_module_attrC   sU     KDFD)E  ''0A0A%0H0H  !1!18<  r   r!   N)__name__r<   __qualname____firstlineno__r6   r>   __static_attributes____classdictcell____classdict__s   @r   r   r      s     %>N= =r   r   r   zNot valid on Windowsc                   \  a  ] tR t^Lt o R tR tR tR tR tR t	]
P                  ! ]P                  P                  R4      R4      R	 4       tR
 t]
P"                  ! ]! ]R4      R4      R 4       t]
P"                  ! ]P*                  R4      ]P.                  ! 4       R 4       4       tRtV tR# )
PosixTestsc                    R # Nr!   r1   argss   &*r   trivial_signal_handler!PosixTests.trivial_signal_handlerN   s    r   c                D    \         P                  ! V P                  V4      # rJ   )	functoolspartialrM   )r1   arguments   &&r   create_handler_with_partial&PosixTests.create_handler_with_partialQ   s      !<!<hGGr   c                    V P                  \        \        P                  R 4       V P                  \        \        P                  R V P                  4       V P                  \        \        P
                  R 4       R# )i  N)assertRaises
ValueErrorr   	getsignalrM   	strsignalr1   s   &r   ,test_out_of_range_signal_number_raises_error7PosixTests.test_out_of_range_signal_number_raises_errorT   sU    *f&6&6=*fmmT55	7 	*f&6&6=r   c                n    V P                  \        \        P                  \        P                  R 4       R # rJ   )rV   	TypeErrorr   SIGUSR1rZ   s   &r   0test_setting_signal_handler_to_none_raises_error;PosixTests.test_setting_signal_handler_to_none_raises_error\   s!    )V]] ..$	0r   c                   \         P                   ! \         P                  V P                  4      pV P                  V\         P                  4       V P                  \         P                  ! \         P                  4      V P                  4       \         P                   ! \         P                  V4       V P                  \         P                  ! \         P                  4      V4       R # rJ   )r   SIGHUPrM   r)   r   r*   rX   )r1   hups   & r   test_getsignalPosixTests.test_getsignal`   s    mmFMM4+F+FGc6??3))&--844	6fmmS)))&--8#>r   c                ^    ! R  R4      pV! 4       pV P                  ^ VP                  4       V P                  V4      p\        P                  ! \        P                  V4      pV P                  V\        P                  4       V P                  \        P                  ! \        P                  4      V4       \        P                  ! \        P                  V4       V P                  \        P                  ! \        P                  4      V4       V P                  ^ VP                  4       R# )c                   8   a a ] tR t^kt oR tV 3R ltRtVtV ;t# )GPosixTests.test_no_repr_is_called_on_signal_handler.<locals>.MyArgumentc                    ^ V n         R# )r   N
repr_countrZ   s   &r   __init__PPosixTests.test_no_repr_is_called_on_signal_handler.<locals>.MyArgument.__init__l   s	    "#r   c                R   < V ;P                   ^,          un         \        SV `	  4       # )   )rl   super__repr__)r1   	__class__s   &r   rr   PPosixTests.test_no_repr_is_called_on_signal_handler.<locals>.MyArgument.__repr__o   s    1$w'))r   rk   )	r@   r<   rA   rB   rm   rr   rC   rD   __classcell__)rs   rF   s   @@r   
MyArgumentri   k   s     $* *r   rv   N)r*   rl   rS   r   rc   r)   r   rX   )r1   rv   rR   handlerrd   s   &    r   (test_no_repr_is_called_on_signal_handler3PosixTests.test_no_repr_is_called_on_signal_handlerh   s    	* 	* <H//0228<mmFMM73c6??3))&--8'BfmmS)))&--8#>H//0r   netbsdz/gh-124083: strsignal is not supported on NetBSDc                >   V P                  R \        P                  ! \        P                  4      4       V P                  R\        P                  ! \        P                  4      4       V P                  R\        P                  ! \        P
                  4      4       R# )	Interrupt
TerminatedHangupN)assertInr   rY   SIGINTSIGTERMrc   rZ   s   &r   test_strsignalPosixTests.test_strsignal~   s[     	k6#3#3FMM#BClF$4$4V^^$DEh 0 0 ?@r   c                    \         P                  P                  \        4      p\         P                  P	                  VR 4      p\        V4       R# )zsignalinterproctester.pyN)ospathdirname__file__joinr   )r1   r   scripts   &  r   test_interprocess_signal#PosixTests.test_interprocess_signal   s1    ''//(+g'AB r   valid_signalszrequires signal.valid_signalsc                   \         P                  ! 4       pV P                  V\        4       V P	                  \         P
                  P                  V4       V P	                  \         P
                  P                  V4       V P                  ^ V4       V P                  \         P                  V4       V P                  \        V4      \         P                  4       \        \         4       F  pVP                  R4      '       g   K  VR9   d   K%  V P                  VR7      ;_uu_ 4        \        \         V4      pV P!                  V^ 4       V P                  V\         P                  4       RRR4       K  	  R#   + '       g   i     K  ; i)r   r   r   N>   r   r    )r   r   r)   setr   r   r   SIGALRMassertNotInNSIG
assertLesslenr'   r   subTestr(   assertGreaterEqual)r1   sr   signums   &   r   test_valid_signalsPosixTests.test_valid_signals   s   
   "a%fnn++Q/fnn,,a0Aa(A, KD??5))--4(( .''24 )(   )((s   )AE::Fsys.executable required.c                   \         P                  ! \        P                  R R.\         P                  R7      pV P                  RVP                  4       V P                  VP                  \        P                  ) 4       R# )-czaimport os, signal, time
os.kill(os.getpid(), signal.SIGINT)
for _ in range(999): time.sleep(0.01)stderr   KeyboardInterruptN)
subprocessrunr+   
executablePIPEr   r   r*   
returncoder   r   )r1   processs   & r   !test_keyboard_interrupt_exit_code,PosixTests.test_keyboard_interrupt_exit_code   s_     ..9: "( 	*GNN;++fmm^<r   r!   N)r@   r<   rA   rB   rM   rS   r[   r`   re   rx   unittestskipIfr+   r,   r   r   r   
skipUnlesshasattrr   r   r   r   requires_subprocessr   rC   rD   rE   s   @r   rH   rH   L   s     H>0?1, __S\\,,X6FHAHA!
 ('5	5, )CD  "	= # E	=r   rH   zWindows specificc                      a  ] tR t^t o R tR t]P                  ! ]P                  R4      ]
P                  ! 4       R 4       4       tRtV tR# )WindowsSignalTestsc                   \         P                  ! 4       pV P                  V\        4       V P	                  \        V4      ^4       V P                  \         P                  P                  V4       V P                  ^ V4       V P                  \         P                  V4       V P                  \        V4      \         P                  4       R# )   N)r   r   r)   r   r   r   r   r   r   r   r   r   r1   r   s   & r   r   %WindowsSignalTests.test_valid_signals   s      "a%A*fnn++Q/Aa(A,r   c                   R  p\        4       p\        P                  \        P                  \        P                  \        P
                  \        P                  \        P                  \        P                  3 FY  p\        P                  ! V4      f   K  \        P                  ! V\        P                  ! W14      4       VP                  V4       K[  	  V P                  V4       V P                  \        4      ;_uu_ 4        \        P                  ! RV4       RRR4       V P                  \        4      ;_uu_ 4        \        P                  ! ^V4       RRR4       R#   + '       g   i     LO; i  + '       g   i     R# ; i)c                     R # rJ   r!   )xys   &&r   r   3WindowsSignalTests.test_issue9324.<locals>.<lambda>   s    tr   N)r   r   SIGABRTSIGBREAKSIGFPESIGILLr   SIGSEGVr   rX   add
assertTruerV   rW   )r1   rw   checkedr2   s   &   r   test_issue9324!WindowsSignalTests.test_issue9324   s    #%NNFOOV]]MM6==&..NN$C
 $0c6==#>?C $ 	 z**MM"g& + z**MM!W% +* +* +**s   E#E6#E3	6F	r   c                    \         P                  ! \        P                  R R.\         P                  R7      pV P                  RVP                  4       RpV P                  VP                  V4       R# )r   zraise KeyboardInterruptr   r   l   :   N)	r   r   r+   r   r   r   r   r*   r   )r1   r   STATUS_CONTROL_C_EXITs   &  r   r   4WindowsSignalTests.test_keyboard_interrupt_exit_code   sZ     ..'@A!( 	*GNN; *++-BCr   r!   N)r@   r<   rA   rB   r   r   r   r   r+   r   r   r   r   rC   rD   rE   s   @r   r   r      sI     -&* )CD  "D # EDr   r   c                   ~  a  ] tR t^t o R tR t]P                  ! ]P                  R4      R 4       t
]P                  ! ]! ]R4      R4      R 4       t]P                  ! ]P                  R4      R 4       t]P                  ! ]P"                  R	8H  R
4      ]P                  ! ]! ]R4      R4      R 4       4       tRtV tR# )WakeupFDTestsc                   V P                  \        4      ;_uu_ 4        \        P                  ! \        P                  R 7       RRR4       V P                  \        4      ;_uu_ 4        \        P                  ! \        P                  R4       RRR4       R#   + '       g   i     L]; i  + '       g   i     R# ; i))r   NF)rV   r^   r   set_wakeup_fdr   rZ   s   &r   test_invalid_callWakeupFDTests.test_invalid_call   sn    y))  6 * y))  6 *)	 *) *))s   &B)&B,B)	,B=	c                    \         P                  ! 4       pV P                  \        \        3\
        P                  V4       R # rJ   )r   make_bad_fdrV   rW   OSErrorr   r   )r1   fds   & r   test_invalid_fdWakeupFDTests.test_invalid_fd   s0    ""$:w/ ..	4r   zneeds working sockets.c                    \         P                   ! 4       pVP                  4       pVP                  4        V P                  \        \
        3\        P                  V4       R # rJ   )socketfilenocloserV   rW   r   r   r   )r1   sockr   s   &  r   test_invalid_socket!WakeupFDTests.test_invalid_socket   sA    }}[[]

:w/ ..	4r   piperequires os.pipe()c                   \         P                  ! 4       w  rV P                  \         P                  V4       V P                  \         P                  V4       \         P                  ! 4       w  r4V P                  \         P                  V4       V P                  \         P                  V4       \	        \         R 4      '       d/   \         P
                  ! VR4       \         P
                  ! VR4       \        P                  ! V4       V P                  \        P                  ! V4      V4       V P                  \        P                  ! R4      V4       V P                  \        P                  ! R4      R4       R# )set_blockingFNr   )	r   r   
addCleanupr   r   r   r   r   r*   )r1   r1w1r2w2s   &    r   test_set_wakeup_fd_result'WakeupFDTests.test_set_wakeup_fd_result   s    "%"%"%"%2~&&OOB&OOB&R --b126--b126--b126r   c                Z   \         P                   ! 4       pV P                  VP                  4       VP                  R 4       VP	                  4       p\         P                   ! 4       pV P                  VP                  4       VP                  R 4       VP	                  4       p\
        P                  ! V4       V P                  \
        P                  ! V4      V4       V P                  \
        P                  ! R4      V4       V P                  \
        P                  ! R4      R4       R# )FNr   )r   r   r   setblockingr   r   r   r*   )r1   sock1fd1sock2fd2s   &    r    test_set_wakeup_fd_socket_result.WakeupFDTests.test_set_wakeup_fd_socket_result  s    $% lln$% llnS!--c2C8--b137--b126r   r   ztests specific to POSIXc                ^   \         P                  ! 4       w  rV P                  \         P                  V4       V P                  \         P                  V4       \         P                  ! VR 4       V P                  \        4      ;_uu_ 4       p\        P                  ! V4       RRR4       V P                  \        XP                  4      RV,          4       \         P                  ! VR4       \        P                  ! V4       \        P                  ! R4       R#   + '       g   i     L; i)TNz&the fd %s must be in non-blocking modeFr   )r   r   r   r   r   rV   rW   r   r   r*   str	exception)r1   rfdwfdcms   &   r   test_set_wakeup_fd_blocking)WakeupFDTests.test_set_wakeup_fd_blocking%  s     779#&#& 	T"z**b  % +R\\*ACG	I 	U#S!R  +*s   DD,	r!   N)r@   r<   rA   rB   r   r   r   r   r   has_socket_supportr   r   r   r   r   r   r+   r,   r   rC   rD   rE   s   @r   r   r      s     74
 335MN4 O4 V,.BC7 D7" 335MN7 O7$ __S\\W,.GHV,.BC! D I!r   r   c                      a  ] tR tRt o ]P
                  ! ]RJ R4      RR/R l4       t]P
                  ! ]RJ R4      ]P                  ! ]	! ]
R4      R4      R	 4       4       tR
 tR tR t]P                  ! ]	! ]R4      R4      R 4       tRtV tR# )WakeupSignalTestsi9  Nneed _testcapiorderedTc               p    R P                  \        \        \        V4      4      W!4      p\	        RV4       R# )a  if 1:
        import _testcapi
        import os
        import signal
        import struct

        signals = {!r}

        def handler(signum, frame):
            pass

        def check_signum(signals):
            data = os.read(read, len(signals)+1)
            raised = struct.unpack('%uB' % len(data), data)
            if not {!r}:
                raised = set(raised)
                signals = set(signals)
            if raised != signals:
                raise Exception("%r != %r" % (raised, signals))

        {}

        signal.signal(signal.SIGALRM, handler)
        read, write = os.pipe()
        os.set_blocking(write, False)
        signal.set_wakeup_fd(write)

        test()
        check_signum(signals)

        os.close(read)
        os.close(write)
        r   N)formattuplemapintr   )r1   	test_bodyr   signalscodes   &&$* r   check_wakeupWakeupSignalTests.check_wakeup;  s5     @ F5S'*+W@A 	D 	t$r   r   r   c                ~   R p\         P                  ! 4       w  r# \         P                  ! VR4       V P                  R4       \         P
                  ! V4       \         P
                  ! V4       \        RV4       R#   \         d     LGi ; i  \         P
                  ! T4       \         P
                  ! T4       i ; i)a'  if 1:
        import _testcapi
        import errno
        import os
        import signal
        import sys
        from test.support import captured_stderr

        def handler(signum, frame):
            1/0

        signal.signal(signal.SIGALRM, handler)
        r, w = os.pipe()
        os.set_blocking(r, False)

        # Set wakeup_fd a read-only file descriptor to trigger the error
        signal.set_wakeup_fd(r)
        try:
            with captured_stderr() as err:
                signal.raise_signal(signal.SIGALRM)
        except ZeroDivisionError:
            # An ignored exception should have been printed out on stderr
            err = err.getvalue()
            if ('Exception ignored while trying to write to the signal wakeup fd'
                not in err):
                raise AssertionError(err)
            if ('OSError: [Errno %d]' % errno.EBADF) not in err:
                raise AssertionError(err)
        else:
            raise AssertionError("ZeroDivisionError not raised")

        os.close(r)
        os.close(w)
           xz9OS doesn't report write() error on the read end of a piper   N)r   r   writeskipTestr   r   r   )r1   r  rws   &   r   test_wakeup_write_error)WakeupSignalTests.test_wakeup_write_errorb  s    !D wwy	HHQ MMUVHHQKHHQKt$  		
 HHQKHHQKs(   A= B =BB 
BB .B<c                F    V P                  R \        P                  4       R# )a  def test():
            import select
            import time

            TIMEOUT_FULL = 10
            TIMEOUT_HALF = 5

            class InterruptSelect(Exception):
                pass

            def handler(signum, frame):
                raise InterruptSelect
            signal.signal(signal.SIGALRM, handler)

            signal.alarm(1)

            # We attempt to get a signal during the sleep,
            # before select is called
            try:
                select.select([], [], [], TIMEOUT_FULL)
            except InterruptSelect:
                pass
            else:
                raise Exception("select() was not interrupted")

            before_time = time.monotonic()
            select.select([read], [], [], TIMEOUT_FULL)
            after_time = time.monotonic()
            dt = after_time - before_time
            if dt >= TIMEOUT_HALF:
                raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
        Nr  r   r   rZ   s   &r   test_wakeup_fd_early&WakeupSignalTests.test_wakeup_fd_early  s     > ^^?	r   c                F    V P                  R \        P                  4       R# )a`  def test():
            import select
            import time

            TIMEOUT_FULL = 10
            TIMEOUT_HALF = 5

            class InterruptSelect(Exception):
                pass

            def handler(signum, frame):
                raise InterruptSelect
            signal.signal(signal.SIGALRM, handler)

            signal.alarm(1)
            before_time = time.monotonic()
            # We attempt to get a signal during the select call
            try:
                select.select([read], [], [], TIMEOUT_FULL)
            except InterruptSelect:
                pass
            else:
                raise Exception("select() was not interrupted")
            after_time = time.monotonic()
            dt = after_time - before_time
            if dt >= TIMEOUT_HALF:
                raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
        Nr  rZ   s   &r   test_wakeup_fd_during'WakeupSignalTests.test_wakeup_fd_during  s     6 ^^7	r   c                d    V P                  R \        P                  \        P                  4       R# )zdef test():
            signal.signal(signal.SIGUSR1, handler)
            signal.raise_signal(signal.SIGUSR1)
            signal.raise_signal(signal.SIGALRM)
        N)r  r   r_   r   rZ   s   &r   test_signumWakeupSignalTests.test_signum  s$      ^^V^^		-r   pthread_sigmaskneed signal.pthread_sigmask()c                h    V P                  R \        P                  \        P                  RR7       R# )a  def test():
            signum1 = signal.SIGUSR1
            signum2 = signal.SIGUSR2

            signal.signal(signum1, handler)
            signal.signal(signum2, handler)

            signal.pthread_sigmask(signal.SIG_BLOCK, (signum1, signum2))
            signal.raise_signal(signum1)
            signal.raise_signal(signum2)
            # Unblocking the 2 signals calls the C signal handler twice
            signal.pthread_sigmask(signal.SIG_UNBLOCK, (signum1, signum2))
        F)r   N)r  r   r_   SIGUSR2rZ   s   &r   test_pendingWakeupSignalTests.test_pending  s-     	  nnfnne 	 	=r   r!   )r@   r<   rA   rB   r   r   	_testcapir  r   r   r   r
  r  r  r  r   r  rC   rD   rE   s   @r   r   r   9  s     __Y$&(89$% $% :$%L __Y$&(89V,.BC1% D :1%f D<- ):;8:=:=r   r   
socketpairzneed socket.socketpairc                      a  ] tR tRt o ]P
                  ! ]RJ R4      R 4       t]P
                  ! ]RJ R4      R 4       t]P
                  ! ]RJ R4      R 4       t	Rt
V tR# )WakeupSocketSignalTestsi  Nr   c                "    R p\        RV4       R# )a  if 1:
        import signal
        import socket
        import struct
        import _testcapi

        signum = signal.SIGINT
        signals = (signum,)

        def handler(signum, frame):
            pass

        signal.signal(signum, handler)

        read, write = socket.socketpair()
        write.setblocking(False)
        signal.set_wakeup_fd(write.fileno())

        signal.raise_signal(signum)

        data = read.recv(1)
        if not data:
            raise Exception("no signum written")
        raised = struct.unpack('B', data)
        if raised != signals:
            raise Exception("%r != %r" % (raised, signals))

        read.close()
        write.close()
        r   Nr   r1   r  s   & r   test_socket#WakeupSocketSignalTests.test_socket  s    > 	t$r   c                v    \         P                  R 8X  d   RpMRpRP                  VR7      p\        RV4       R# )ntsendr  a,  if 1:
        import errno
        import signal
        import socket
        import sys
        import time
        import _testcapi
        from test.support import captured_stderr

        signum = signal.SIGINT

        def handler(signum, frame):
            pass

        signal.signal(signum, handler)

        read, write = socket.socketpair()
        read.setblocking(False)
        write.setblocking(False)

        signal.set_wakeup_fd(write.fileno())

        # Close sockets: send() will fail
        read.close()
        write.close()

        with captured_stderr() as err:
            signal.raise_signal(signum)

        err = err.getvalue()
        if ('Exception ignored while trying to {action} to the signal wakeup fd'
            not in err):
            raise AssertionError(err)
        actionr   Nr   r   r   r   r1   r)  r  s   &  r   test_send_error'WakeupSocketSignalTests.test_send_error  s@     77d?FF!B F&F!C 	D 	t$r   c                v    \         P                  R 8X  d   RpMRpRP                  VR7      p\        RV4       R# )r&  r'  r  aK  if 1:
        import errno
        import signal
        import socket
        import sys
        import time
        import _testcapi
        from test.support import captured_stderr

        signum = signal.SIGINT

        # This handler will be called, but we intentionally won't read from
        # the wakeup fd.
        def handler(signum, frame):
            pass

        signal.signal(signum, handler)

        read, write = socket.socketpair()

        # Fill the socketpair buffer
        if sys.platform == 'win32':
            # bpo-34130: On Windows, sometimes non-blocking send fails to fill
            # the full socketpair buffer, so use a timeout of 50 ms instead.
            write.settimeout(0.050)
        else:
            write.setblocking(False)

        written = 0
        if sys.platform == "vxworks":
            CHUNK_SIZES = (1,)
        else:
            # Start with large chunk size to reduce the
            # number of send needed to fill the buffer.
            CHUNK_SIZES = (2 ** 16, 2 ** 8, 1)
        for chunk_size in CHUNK_SIZES:
            chunk = b"x" * chunk_size
            try:
                while True:
                    write.send(chunk)
                    written += chunk_size
            except (BlockingIOError, TimeoutError):
                pass

        print(f"%s bytes written into the socketpair" % written, flush=True)

        write.setblocking(False)
        try:
            write.send(b"x")
        except BlockingIOError:
            # The socketpair buffer seems full
            pass
        else:
            raise AssertionError("%s bytes failed to fill the socketpair "
                                 "buffer" % written)

        # By default, we get a warning when a signal arrives
        msg = ('Exception ignored while trying to {action} '
               'to the signal wakeup fd')
        signal.set_wakeup_fd(write.fileno())

        with captured_stderr() as err:
            signal.raise_signal(signum)

        err = err.getvalue()
        if msg not in err:
            raise AssertionError("first set_wakeup_fd() test failed, "
                                 "stderr: %r" % err)

        # And also if warn_on_full_buffer=True
        signal.set_wakeup_fd(write.fileno(), warn_on_full_buffer=True)

        with captured_stderr() as err:
            signal.raise_signal(signum)

        err = err.getvalue()
        if msg not in err:
            raise AssertionError("set_wakeup_fd(warn_on_full_buffer=True) "
                                 "test failed, stderr: %r" % err)

        # But not if warn_on_full_buffer=False
        signal.set_wakeup_fd(write.fileno(), warn_on_full_buffer=False)

        with captured_stderr() as err:
            signal.raise_signal(signum)

        err = err.getvalue()
        if err != "":
            raise AssertionError("set_wakeup_fd(warn_on_full_buffer=False) "
                                 "test failed, stderr: %r" % err)

        # And then check the default again, to make sure warn_on_full_buffer
        # settings don't leak across calls.
        signal.set_wakeup_fd(write.fileno())

        with captured_stderr() as err:
            signal.raise_signal(signum)

        err = err.getvalue()
        if msg not in err:
            raise AssertionError("second set_wakeup_fd() test failed, "
                                 "stderr: %r" % err)

        r(  r   Nr*  r+  s   &  r   test_warn_on_full_buffer0WakeupSocketSignalTests.test_warn_on_full_bufferB  sA     77d?FFgN F&F!O 	P 	t$r   r!   )r@   r<   rA   rB   r   r   r  r#  r,  r/  rC   rD   rE   s   @r   r  r    sx      __Y$&(89!% :!%F __Y$&(89(% :(%T __Y$&(89n% :n%r   r  siginterruptzneeds signal.siginterrupt()r   r   c                   |   a  ] tR tRt o ]P
                  3R ltR tR t]P                  ! R4      R 4       t
RtV tR# )	SiginterruptTesti  c                   R V: R2p\        RV4      ;_uu_ 4       p VP                  P                  4       pVP                  VR7      w  rgWV,           pVP	                  4       pVR9  d   \        RV: RV: 24      hV^8H  uuRRR4       #   \        P                   d    TP                  4         RRR4       R# i ; i  + '       g   i     R# ; i)	zif 1:
            import errno
            import os
            import signal
            import sys

            interrupt = aq  
            r, w = os.pipe()

            def handler(signum, frame):
                1 / 0

            signal.signal(signal.SIGALRM, handler)
            if interrupt is not None:
                signal.siginterrupt(signal.SIGALRM, interrupt)

            print("ready")
            sys.stdout.flush()

            # run the test twice
            try:
                for loop in range(2):
                    # send a SIGALRM in a second (during the read)
                    signal.alarm(1)
                    try:
                        # blocking call: read from a pipe without data
                        os.read(r, 1)
                    except ZeroDivisionError:
                        pass
                    else:
                        sys.exit(2)
                sys.exit(3)
            finally:
                os.close(r)
                os.close(w)
        r   timeoutChild error (exit code ): NF)      )	r	   stdoutreadlinecommunicatewait	Exceptionr   TimeoutExpiredkill)	r1   	interruptr6  r  r   
first_liner;  r   exitcodes	   &&&      r   readpipe_interrupted%SiginterruptTest.readpipe_interrupted  s    T G#H $%%'$^^446
!(!4!4W!4!E
 $,"<<>6)#'/%9 : : A &% ,,  &% &%%s.   C.B6C%B>2C=B>>CC	c                J    V P                  R 4      pV P                  V4       R # rJ   rE  r   r1   interrupteds   & r   test_without_siginterrupt*SiginterruptTest.test_without_siginterrupt        //5$r   c                J    V P                  R 4      pV P                  V4       R# TNrH  rI  s   & r   test_siginterrupt_on%SiginterruptTest.test_siginterrupt_on  rM  r   walltimec                N    V P                  R ^R7      pV P                  V4       R# )Fr5  N)rE  assertFalserI  s   & r   test_siginterrupt_off&SiginterruptTest.test_siginterrupt_off  s'    
 //q/A%r   r!   N)r@   r<   rA   rB   r   SHORT_TIMEOUTrE  rK  rP  requires_resourcerU  rC   rD   rE   s   @r   r3  r3    s?      7>6K6K :'x%% z*& +&r   r3  	getitimer	setitimerz/needs signal.getitimer() and signal.setitimer()c                      a  ] tR tRt o R tR tR tR tR tR t	R t
]P                  ! ]P                  R9   ;'       g    ]R	4      R
 4       tR tR tRtV tR# )
ItimerTesti  c                    R V n         ^ V n        RV n        \        P                  ! \        P                  V P
                  4      V n        R# )FN)hndl_called
hndl_countitimerr   r   sig_alrm	old_alarmrZ   s   &r   setUpItimerTest.setUp  s2     v~~t}}Er   c                    \         P                   ! \         P                  V P                  4       V P                  e$   \         P                  ! V P                  ^ 4       R # R # rJ   )r   r   rb  r`  rZ  rZ   s   &r   tearDownItimerTest.tearDown  s;    fnndnn5;;"T[[!, #r   c                    R V n         R# rO  )r^  rK   s   &*r   ra  ItimerTest.sig_alrm  s
    r   c                    R V n         V P                  ^8  d   \        P                  ! R4      hV P                  ^8X  d&   \        P                  ! \        P
                  ^ 4       V ;P                  ^,          un        R# )Tz.setitimer didn't disable ITIMER_VIRTUAL timer.N)r^  r_  r   ItimerErrorrZ  ITIMER_VIRTUALrK   s   &*r   
sig_vtalrmItimerTest.sig_vtalrm   s^    ??Q$$ &  __!V22A61r   c                ^    R V n         \        P                  ! \        P                  ^ 4       R# rO  )r^  r   rZ  ITIMER_PROFrK   s   &*r   sig_profItimerTest.sig_prof-  s     ++Q/r   c                f    V P                  \        P                  \        P                  R^ 4       R# )rp   Nr   )rV   r   rk  rZ  ITIMER_REALrZ   s   &r   test_itimer_excItimerTest.test_itimer_exc1  s'     	&,,f.>.>AFr   c                    \         P                  V n        \         P                  ! V P                  R 4       \         P                  ! 4        V P                  V P                  R4       R# )      ?TN)r   rt  r`  rZ  pauser*   r^  rZ   s   &r   test_itimer_realItimerTest.test_itimer_real:  sB    ((c*))40r   zDitimer not reliable (does not mix well with threading) on some BSDs.c                D   \         P                  V n        \         P                   ! \         P                  V P                  4       \         P
                  ! V P                  R R 4       \        P                  ! \        P                  4       FE  p\        R \        R4       4       4      p\         P                  ! V P                  4      R8X  g   KE   M	  V P                  \         P                  ! V P                  4      R4       V P                  V P                  R4       R# )MbP?c              3   2   "   T F  qV,          x  K  	  R # 5irJ   r!   .0is   & r   	<genexpr>1ItimerTest.test_itimer_virtual.<locals>.<genexpr>J       0<aEE<   TN順         r  )r   rl  r`  	SIGVTALRMrm  rZ  r   
busy_retryLONG_TIMEOUTsumrangerY  r*   r^  r1   _s   & r   test_itimer_virtualItimerTest.test_itimer_virtualA  s     ++f&&8eU3##G$8$89A05<00A,
: : 	))$++6
C))40r   c                D   \         P                  V n        \         P                   ! \         P                  V P                  4       \         P
                  ! V P                  R R 4       \        P                  ! \        P                  4       FE  p\        R \        R4       4       4      p\         P                  ! V P                  4      R8X  g   KE   M	  V P                  \         P                  ! V P                  4      R4       V P                  V P                  R4       R# )g?c              3   2   "   T F  qV,          x  K  	  R # 5irJ   r!   r  s   & r   r  .ItimerTest.test_itimer_prof.<locals>.<genexpr>[  r  r  TNr  r  )r   rp  r`  SIGPROFrq  rZ  r   r  r  r  r  rY  r*   r^  r  s   & r   test_itimer_profItimerTest.test_itimer_profT  s    ((fnndmm4c3/##G$8$89A05<00A,
: : 	))$++6
C))40r   c                    \         P                  V n        \         P                  ! V P                  R 4       \        P
                  ! ^4       V P                  V P                  R4       R# )ư>TN)r   rt  r`  rZ  timesleepr*   r^  rZ   s   &r   test_setitimer_tinyItimerTest.test_setitimer_tinye  sF     ((d+

1))40r   )r^  r_  r`  rb  N)netbsd5)r@   r<   rA   rB   rc  rf  ra  rm  rq  ru  rz  r   r   r+   r,   r   r  r  r  rC   rD   rE   s   @r   r\  r\    sn     F- 0H1 __S\\\1DD_NP1P1"1"1 1r   r\  c                     a  ] tR tRt o ]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      ]P
                  ! ]! ]R4      R4      R 4       4       t	]P
                  ! ]! ]R4      R	4      ]
P                  ! 4       R
 4       4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      ]P
                  ! ]! ]R4      R4      ]
P                  ! 4       R 4       4       4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      R 4       t]P
                  ! ]! ]R4      R4      ]
P                  ! 4       R 4       4       t]P
                  ! ]! ]R4      R	4      ]
P                  ! 4       R 4       4       tRtV tR# )PendingSignalsTestsio  
sigpendingzneed signal.sigpending()c                `    V P                  \        P                  ! 4       \        4       4       R # rJ   )r*   r   r  r   rZ   s   &r   test_sigpending_empty)PendingSignalsTests.test_sigpending_emptyt  s     	**,ce4r   r  r  c                "    R p\        RV4       R# )a  if 1:
            import os
            import signal

            def handler(signum, frame):
                1/0

            signum = signal.SIGUSR1
            signal.signal(signum, handler)

            signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
            os.kill(os.getpid(), signum)
            pending = signal.sigpending()
            for sig in pending:
                assert isinstance(sig, signal.Signals), repr(pending)
            if pending != {signum}:
                raise Exception('%s != {%s}' % (pending, signum))
            try:
                signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
            except ZeroDivisionError:
                pass
            else:
                raise Exception("ZeroDivisionError not raised")
        r   Nr!  r"  s   & r   test_sigpending#PendingSignalsTests.test_sigpendingy  s    
0 	t$r   pthread_killzneed signal.pthread_kill()c                "    R p\        RV4       R# )a  if 1:
            import signal
            import threading
            import sys

            signum = signal.SIGUSR1

            def handler(signum, frame):
                1/0

            signal.signal(signum, handler)

            tid = threading.get_ident()
            try:
                signal.pthread_kill(tid, signum)
            except ZeroDivisionError:
                pass
            else:
                raise Exception("ZeroDivisionError not raised")
        r   Nr!  r"  s   & r   test_pthread_kill%PendingSignalsTests.test_pthread_kill  s    ( 	t$r   c                P    R VP                  4       : RV: R2p\        RV4       R# )zif 1:
        import signal
        import sys
        from signal import Signals

        def handler(signum, frame):
            1/0

        z

        blocked = a  
        signum = signal.SIGALRM

        # child: block and wait the signal
        try:
            signal.signal(signum, handler)
            signal.pthread_sigmask(signal.SIG_BLOCK, [blocked])

            # Do the tests
            test(signum)

            # The handler must not be called on unblock
            try:
                signal.pthread_sigmask(signal.SIG_UNBLOCK, [blocked])
            except ZeroDivisionError:
                print("the signal handler has been called",
                      file=sys.stderr)
                sys.exit(1)
        except BaseException as err:
            print("error: {}".format(err), file=sys.stderr)
            sys.stderr.flush()
            sys.exit(1)
        r   N)stripr   )r1   blockedtestr  s   &&& r   wait_helperPendingSignalsTests.wait_helper  s%    N zz|WA &J 	t$r   sigwaitzneed signal.sigwait()c                F    V P                  \        P                  R 4       R# )a   
        def test(signum):
            signal.alarm(1)
            received = signal.sigwait([signum])
            assert isinstance(received, signal.Signals), received
            if received != signum:
                raise Exception('received %s, not %s' % (received, signum))
        Nr  r   r   rZ   s   &r   test_sigwait PendingSignalsTests.test_sigwait  s     	 * 	r   sigwaitinfozneed signal.sigwaitinfo()c                F    V P                  \        P                  R 4       R# )z
        def test(signum):
            signal.alarm(1)
            info = signal.sigwaitinfo([signum])
            if info.si_signo != signum:
                raise Exception("info.si_signo != %s" % signum)
        Nr  rZ   s   &r   test_sigwaitinfo$PendingSignalsTests.test_sigwaitinfo       	 * 	r   sigtimedwaitzneed signal.sigtimedwait()c                F    V P                  \        P                  R 4       R# )z
        def test(signum):
            signal.alarm(1)
            info = signal.sigtimedwait([signum], 10.1000)
            if info.si_signo != signum:
                raise Exception('info.si_signo != %s' % signum)
        Nr  rZ   s   &r   test_sigtimedwait%PendingSignalsTests.test_sigtimedwait  r  r   c                F    V P                  \        P                  R 4       R# )z
        def test(signum):
            import os
            os.kill(os.getpid(), signum)
            info = signal.sigtimedwait([signum], 0)
            if info.si_signo != signum:
                raise Exception('info.si_signo != %s' % signum)
        Nr  rZ   s   &r   test_sigtimedwait_poll*PendingSignalsTests.test_sigtimedwait_poll  s     	 * 	r   c                F    V P                  \        P                  R 4       R# )z
        def test(signum):
            received = signal.sigtimedwait([signum], 1.0)
            if received is not None:
                raise Exception("received=%r" % (received,))
        Nr  rZ   s   &r   test_sigtimedwait_timeout-PendingSignalsTests.test_sigtimedwait_timeout  s     	 * 	r   c                t    \         P                  pV P                  \        \         P                  V.R4       R# )rx  Ng      )r   r   rV   rW   r  )r1   r   s   & r   "test_sigtimedwait_negative_timeout6PendingSignalsTests.test_sigtimedwait_negative_timeout  s)     *f&9&9F8TJr   c                    \        R R4       R# )r   a  if True:
            import os, threading, sys, time, signal

            # the default handler terminates the process
            signum = signal.SIGUSR1

            def kill_later():
                # wait until the main thread is waiting in sigwait()
                time.sleep(1)
                os.kill(os.getpid(), signum)

            # the signal must be blocked by all the threads
            signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
            killer = threading.Thread(target=kill_later)
            killer.start()
            received = signal.sigwait([signum])
            if received != signum:
                print("sigwait() received %s, not %s" % (received, signum),
                      file=sys.stderr)
                sys.exit(1)
            killer.join()
            # unblock the signal, which should have been cleared by sigwait()
            signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
        Nr!  rZ   s   &r   test_sigwait_thread'PendingSignalsTests.test_sigwait_thread  s     	   	r   c                   V P                  \        \        P                  4       V P                  \        \        P                  ^4       V P                  \        \        P                  ^^^4       V P                  \        \        P                  R. 4       V P                  \
        4      ;_uu_ 4        \        P                  ! \        P                  \        P                  .4       RRR4       V P                  \
        4      ;_uu_ 4        \        P                  ! \        P                  ^ .4       RRR4       V P                  \
        4      ;_uu_ 4        \        P                  ! \        P                  ^R,          .4       RRR4       R#   + '       g   i     L; i  + '       g   i     Lx; i  + '       g   i     R# ; i)rp   i  Ni  )rV   r^   r   r  r   rW   r$   r   rZ   s   &r   test_pthread_sigmask_arguments2PendingSignalsTests.test_pthread_sigmask_argumentsB  s    	)V%;%;<)V%;%;Q?)V%;%;Q1E'6#9#94Dz**""6#3#3fkk]C +z**""6#3#3aS9 +z**""6#3#3agY? +*	 +******s$   45F'F%.F8F"	%F5	8G		c                   \         P                  ! \         P                  \         P                  ! 4       4      pV P	                  \         P                  \         P
                  V4       \         P                  ! \         P                  \         P                  ! 4       4      pV P                  V\         P                  ! 4       4       R # rJ   )r   r  r$   r   r   r&   r%   assertLessEqualr   s   & r   "test_pthread_sigmask_valid_signals6PendingSignalsTests.test_pthread_sigmask_valid_signalsP  s{     ""6#3#3V5I5I5KL..0B0BAF""6#5#5v7K7K7MNQ 4 4 67r   c                "    R p\        RV4       R# )a-	  if 1:
        import signal
        import os; import threading

        def handler(signum, frame):
            1/0

        def kill(signum):
            os.kill(os.getpid(), signum)

        def check_mask(mask):
            for sig in mask:
                assert isinstance(sig, signal.Signals), repr(sig)

        def read_sigmask():
            sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, [])
            check_mask(sigmask)
            return sigmask

        signum = signal.SIGUSR1

        # Install our signal handler
        old_handler = signal.signal(signum, handler)

        # Unblock SIGUSR1 (and copy the old mask) to test our signal handler
        old_mask = signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
        check_mask(old_mask)
        try:
            kill(signum)
        except ZeroDivisionError:
            pass
        else:
            raise Exception("ZeroDivisionError not raised")

        # Block and then raise SIGUSR1. The signal is blocked: the signal
        # handler is not called, and the signal is now pending
        mask = signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
        check_mask(mask)
        kill(signum)

        # Check the new mask
        blocked = read_sigmask()
        check_mask(blocked)
        if signum not in blocked:
            raise Exception("%s not in %s" % (signum, blocked))
        if old_mask ^ blocked != {signum}:
            raise Exception("%s ^ %s != {%s}" % (old_mask, blocked, signum))

        # Unblock SIGUSR1
        try:
            # unblock the pending signal calls immediately the signal handler
            signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
        except ZeroDivisionError:
            pass
        else:
            raise Exception("ZeroDivisionError not raised")
        try:
            kill(signum)
        except ZeroDivisionError:
            pass
        else:
            raise Exception("ZeroDivisionError not raised")

        # Check the new mask
        unblocked = read_sigmask()
        if signum in unblocked:
            raise Exception("%s in %s" % (signum, unblocked))
        if blocked ^ unblocked != {signum}:
            raise Exception("%s ^ %s != {%s}" % (blocked, unblocked, signum))
        if old_mask != unblocked:
            raise Exception("%s != %s" % (old_mask, unblocked))
        r   Nr!  r"  s   & r   test_pthread_sigmask(PendingSignalsTests.test_pthread_sigmaskY  s    GP 	t$r   c                    R p\        RV4      ;_uu_ 4       pVP                  4       w  r4VP                  4       pV^8w  d   \        RV: RV: 24      h RRR4       R#   + '       g   i     R# ; i)a7  if True:
            import threading
            import signal
            import sys

            def handler(signum, frame):
                sys.exit(3)

            signal.signal(signal.SIGUSR1, handler)
            signal.pthread_kill(threading.get_ident(), signal.SIGUSR1)
            sys.exit(2)
        r   r7  r8  N)r	   r=  r>  r?  )r1   r  r   r;  r   rD  s   &     r   test_pthread_kill_main_thread1PendingSignalsTests.test_pthread_kill_main_thread  sg     $%%$002NF||~H1}!)6!3 4 4  &%%%s   =AA0	r!   N)r@   r<   rA   rB   r   r   r   r   r  r  r   requires_working_threadingr  r  r  r  r  r  r  r  r  r  r  r  r  rC   rD   rE   s   @r   r  r  o  s    
 635555 ):;8:635%5:%6 857002% 37%. ):;8:*%:*%X 3022 7466 8577 857	7	 8577 857K7K 302):;8:002 3:2
< ):;8:
@:
@ ):;8:8:8 ):;8:002I% 3:I%V 8570024 374r   r  c                   p  a  ] tR tRt o R tR tR t]P                  ! ]	! ]
R4      R4      R 4       t]P                  ! ]	! ]
R4      R4      R 4       t]P                  ! R	4      ]P                  ! ]R
4      ]P                  ! ]	! ]
R4      R4      ]P$                  ! 4       R 4       4       4       4       tRtV tR# )
StressTesti  c                r    \         P                   ! W4      pV P                  \         P                   W4       R # rJ   )r   r   )r1   r   rw   old_handlers   &&& r   setsigStressTest.setsig  s"    mmF4v;r   c                4  aa ^o. oRVV3R llpV P                  \        P                  \        P                  ^ 4       V P	                  \        P
                  V4       V! 4        \        S4      S8  d   \        P                  ! R4       K(  \        \        S4      ^,
          4       Uu. uF!  pSV^,           ,          SV,          ,
          NK#  	  pp\        P                  ! V4      p\        P                  '       d   \        RV3,          4       V# u upi )   c                    < \        S4      S8  dL   SP                  \        P                  ! 4       4       \        P
                  ! \        P                  R 4       R# R# )r  N)r   appendr  perf_counterr   rZ  rt  )r   frameNtimess   &&r   rw   5StressTest.measure_itimer_resolution.<locals>.handler  s@    5zA~T..01   !3!3T: r   r}  z,detected median itimer() resolution: %.6f s.NN)r   r   rZ  rt  r  r   r   r  r  r  
statisticsmedianr   verboseprint)r1   rw   r  	durationsmedr  r  s   &    @@r   measure_itimer_resolution$StressTest.measure_itimer_resolution  s    	; 	; 	((&*<*<a@FNNG,	%j1nJJt49#e*q.4IJ4IqU1Q3Z%(**4I	J	*???@C6IJ
	 Ks   +'Dc                |    V P                  4       pVR 8:  d   R# VR8:  d   ^d# V P                  RV3,          4       R# )g-C6?i'  g{Gz?z^detected itimer resolution (%.3f s.) too high (> 10 ms.) on this platform (or system too busy)N)r  r  )r1   resos   & r   decide_itimer_countStressTest.decide_itimer_count  sB     --/4<T\MM M!G$ %r   rZ  ztest needs setitimer()c                  a V P                  4       p. oR  pRV3R llpV P                  \        P                  V4       V P                  \        P                  V4       V P                  \        P
                  V4       ^ p\        P                  ! 4       \        P                  ,           pWA8  Ed   \        P                  ! \        P                  ! 4       \        P                  4       V^,          p\        S4      V8  d3   \        P                  ! 4       V8  d   \        P                  ! R4       KB  \        P                  ! \        P                  ! 4       \        P                  4       V^,          p\        S4      V8  g   K  \        P                  ! 4       V8  g   K  \        P                  ! R4       KF  V P                  \        S4      VR4       R# )c                     \         P                  ! \         P                  R \        P                  ! 4       R,          ,           4       R# )r  h㈵>N)r   rZ  rt  random)r   r  s   &&r   first_handler@StressTest.test_stress_delivery_dependent.<locals>.first_handler  s*     V//$8N1NOr   Nc                 *   < SP                  V 4       R # rJ   r  r   r  sigss   &&r   second_handlerAStressTest.test_stress_delivery_dependent.<locals>.second_handler      KKr   r  Some signals were lostr  )r  r  r   r  r_   r   r  	monotonicr   rW  r   rA  getpidr   r  r*   )r1   r  r  r   expected_sigsdeadliner  s   &     @r   test_stress_delivery_dependent)StressTest.test_stress_delivery_dependent  s&    $$&	P	  	FNNM2FNNM2FNNN3>>#g&;&;;GGBIIK0QMd)m+0@80K

4 GGBIIK0QMd)m+0@80K

4  	TA'?@r   c                  a V P                  4       p. oV3R  lpV P                  \        P                  V4       V P                  \        P                  V4       ^ pW18  d   \        P
                  ! \        P                  R\        P                  ! 4       R,          ,           4       \        P                  ! \        P                  ! 4       \        P                  4       V^,          p\        P                  ! \        P                  4       F  p\        S4      V8  g   K   K  	  K  V P                  \        S4      VR4       R# )c                 *   < SP                  V 4       R # rJ   r  r  s   &&r   rw   =StressTest.test_stress_delivery_simultaneous.<locals>.handler*  r  r   r  r  r  N)r  r  r   r  r   rZ  rt  r  r   rA  r  r   sleeping_retryrW  r   r*   )r1   r  rw   r  r  r  s   &    @r   !test_stress_delivery_simultaneous,StressTest.test_stress_delivery_simultaneous!  s     $$&	  	FNNG,FNNG, V//$8N1NOGGBIIK0QM++G,A,ABt9- C 	TA'?@r   z/gh-121065: test is flaky on free-threaded buildz&crashes due to system bug (FB13453490)r_   ztest needs SIGUSR1c                X  aaa	a
a \         P                  o^ o
^ o	RoV	3R loVV
V3R lpVV	V
V3R lp\         P                   ! SS4      pV P                  \         P                   SV4       \        P                  ! VR7      p Rp\
        P                  ! 4       ;_uu_ 4       pVP                  4        V! 4        RoVP                  4        VP                  ea   V P                  VP                  P                  \        4       V P                  RSR	 R
2\        VP                  P                  4      4       RpRRR4       V'       g   V P                  S	^ 4       V P!                  S	S
4       RoVP                  4        R#   + '       g   i     LP; i  RoTP                  4        i ; i)r   Fc                    < S^,          oR# rp   Nr!   )r   r  num_received_signalss   &&r   custom_handlerAStressTest.test_stress_modifying_handlers.<locals>.custom_handlerP  s     A% r   c                  Z   < S '       g"   \         P                  ! S4       S^,          oK)  R# r  )r   raise_signal)do_stopnum_sent_signalsr   s   r   set_interruptsAStressTest.test_stress_modifying_handlers.<locals>.set_interruptsT  s$    ##F+ A%  r   c                     < S^d8  g   S^8  dE   \        R4       F3  p S\        P                  3 F  p\        P                  ! SV4       K  	  K5  	  KR  R# )d   i N  N)r  r   r    )r  rw   r  r  r  r   s     r   cycle_handlersAStressTest.test_stress_modifying_handlers.<locals>.cycle_handlersZ  sI    "S(,@1,DuA$2FNN#Cfg6 $D & -Er   )targetTNzSignal dz ignored due to race condition)r   r_   r   	threadingThreadr   catch_unraisable_exceptionstartr   
unraisabler)   	exc_valuer   r   r   assertGreaterr  )r1   r  r  r  tignoredr   r  r  r  r  r   s   &      @@@@@r   test_stress_modifying_handlers)StressTest.test_stress_modifying_handlersD  sP     	&	&	7 	7 mmFN;v{;N3	G3355	 ==, ))"--*A*A7KMM!&+IJBMM3346 #G 6$ ""#7;  !57GHGFFH1 65. GFFHs+   F "BF:F 
$F F	F F)r!   N)r@   r<   rA   rB   r  r  r  r   r   r   r   r  r  r   requires_gil_enabledr   r   r   r  r+  rC   rD   rE   s   @r   r  r    s     <0% 513*A3*AX 513A3AB !!"ST__XGH3-/0026 3/ I U
6r   r  c                   ~   a  ] tR tRt o R t]P                  ! ]P                  R8g  R4      R 4       t	R t
R tRtV tR	# )
RaiseSignalTesti  c                    V P                  \        4      ;_uu_ 4        \        P                  ! \        P                  4       R R R 4       R #   + '       g   i     R # ; irJ   )rV   KeyboardInterruptr   r  r   rZ   s   &r   test_sigintRaiseSignalTest.test_sigint  s5    011. 2111s   %AA	r   zWindows specific testc                     ^p\         P                  ! V4       V P                  R4       R#   \         d,   pTP                  \        P
                  8X  d    Rp?R# h Rp?ii ; i)rp   z#OSError (Invalid argument) expectedN)r   r  failr   errnoEINVAL)r1   rc   es   &  r   test_invalid_argument%RaiseSignalTest.test_invalid_argument  sM    	F'II;< 	ww%,,&		s   )- A#AAA#c                *  a R oV3R lp\         P                   ! \         P                  V4      pV P                  \         P                   \         P                  V4       \         P                  ! \         P                  4       V P	                  S4       R# )Fc                    < R oR# rO  r!   )abis_oks   &&r   rw   -RaiseSignalTest.test_handler.<locals>.handler  s    Er   N)r   r   r   r  r   )r1   rw   
old_signalr?  s   &  @r   test_handlerRaiseSignalTest.test_handler  sY    	 ]]6==':
v}}jAFMM*r   c                L    R p\        RV4      w  r#pV P                  RV4       R# )zif 1:
        import _thread
        class Foo():
            def __del__(self):
                _thread.interrupt_main()

        x = Foo()
        r   s/   OSError: Signal 2 ignored due to race conditionN)r   r   )r1   r  rcouterrs   &    r   test__thread_interrupt_main+RaiseSignalTest.test__thread_interrupt_main  s*     (d3H#Nr   r!   N)r@   r<   rA   rB   r2  r   r   r+   r,   r9  rB  rH  rC   rD   rE   s   @r   r/  r/    sE     / __S\\W,.EF	 G		O Or   r/  c                   `   a  ] tR tRt o ]P
                  ! ]! ]R4      R4      R 4       tRt	V t
R# )PidfdSignalTesti  pidfd_send_signalzpidfd support not built inc                \   V P                  \        4      ;_uu_ 4       p\        P                  ! ^ \        P                  4       RRR4       XP
                  P                  \        P                  8X  d   V P                  R4       M:VP
                  P                  \        P                  8X  d   V P                  R4       V P                  VP
                  P                  \        P                  4       \        P                  ! R\        P                  ! 4        2\        P                  4      pV P!                  \        P"                  V4       V P%                  \&        R4      ;_uu_ 4        \        P                  ! V\        P                  \)        4       ^ 4       RRR4       V P                  \*        4      ;_uu_ 4        \        P                  ! V\        P                  4       RRR4       R#   + '       g   i     EL; i  + '       g   i     Lq; i  + '       g   i     R# ; i)r   Nzkernel does not support pidfdsz"Not enough privileges to use pidfsz/proc/z^siginfo must be None$)rV   r   r   rL  r   r   r6  ENOSYSr  EPERMr*   EBADFr   openr  O_DIRECTORYr   r   assertRaisesRegexr^   objectr1  )r1   r   my_pidfds   &  r   test_pidfd_send_signal&PidfdSignalTest.test_pidfd_send_signal  sI   
 w''2$$Q6 (<<-MM:;\\5;;.MM>?++U[[977VBIIK=12>>B(+##I/GHH$$Xv}}fhJ I011$$Xv}}= 21 ('' IH111s#   &G3.0H&H3H	H	H+	r!   N)r@   r<   rA   rB   r   r   r   r   rV  rC   rD   rE   s   @r   rK  rK    s0     +,$>	>r   rK  c                  0    \         P                  ! 4        R # rJ   )r   reap_childrenr!   r   r   tearDownModulerZ    s    r   __main__)/r-   r6  rP   r9   r   r  r   r   r  r   r+   r"  r  r   r  r   test.supportr   r   r   r   test.support.script_helperr   r	   r  ImportErrorTestCaser   r   r,   rH   r   r   r   r   r   r  r   r3  r\  r  r  r/  rK  rZ  r@   mainr!   r   r   <module>ra     s       	      
      F
/=8$$ /=d 
(*@Ac="" c= Bc=T 
S\\W,.@A-D** -D B-D`N!H%% N!b 
(*@As=)) s= Bs=l 
WV\24LM@%h// @% N@%F 
(*@A	WV^46ST	WR(*>?R&x(( R& @  U BR&j 
(*@A	WV[1RRgfk6RJL\1"" \1L B\1~P4(++ P4f
}"" }@)Oh'' )OZ>h'' >* zMMO c-  Is   J; ;	KK