ó {G_Tc@shddlZddlmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZe jdkrÌejde jƒ‚ndefd„ƒYZd „Zd „Zeje jd kd ƒd ejfd„ƒYƒZeje jd kd ƒdejfd„ƒYƒZeje jd kdƒdejfd„ƒYƒZdejfd„ƒYZeje jd kd ƒdejfd„ƒYƒZeje jd kd ƒdejfd„ƒYƒZeje jd kd ƒdejfd„ƒYƒZd„Ze dkrdeƒndS(iÿÿÿÿN(t test_support(tclosingtos2triscossCan't test signal on %stHandlerBCalledcBseZRS((t__name__t __module__(((s,/usr/local/lib/python2.7/test/test_signal.pyRscCstjdƒdS(sñUse os._exit(0) to exit the current subprocess. Otherwise, the test catches the SystemExit and continues executing in parallel with the original test, so you wind up with an exponential number of tests running concurrently. iN(tost_exit(((s,/usr/local/lib/python2.7/test/test_signal.pytexit_subprocessscOsDy|||ŽSWn,tk r?}|jtjkr;‚ndSXdS(N(tEnvironmentErrorterrnotEINTRtNone(t__functargstkwargste((s,/usr/local/lib/python2.7/test/test_signal.pytignoring_eintrs twin32sNot valid on WindowstInterProcessSignalTestscBsteZdZd„Zd„Zd d„Zd„Zd„Zd„Z d„Z e j e jdkd ƒd „ƒZRS( icCstjƒ|_tjƒdS(N(tgct isenabledtusing_gctdisable(tself((s,/usr/local/lib/python2.7/test/test_signal.pytsetUp+scCs|jrtjƒndS(N(RRtenable(R((s,/usr/local/lib/python2.7/test/test_signal.pyttearDown/s cCsdjtj|d|ƒƒS(Nttlimit(tjoint tracebackt format_stack(RtframeR((s,/usr/local/lib/python2.7/test/test_signal.pyt format_frame3scCs7t|_tjr3d||j|ddƒfGHndS(Ns&handlerA invoked from signal %s at: %sRi(tTrueta_calledRtverboseR#(RtsignumR"((s,/usr/local/lib/python2.7/test/test_signal.pythandlerA6s  cCsOt|_tjr3d||j|ddƒfGHnt||j|ƒƒ‚dS(Ns&handlerB invoked from signal %s at: %sRi(R$tb_calledRR&R#R(RR'R"((s,/usr/local/lib/python2.7/test/test_signal.pythandlerB<s   cCsQxJtrLy|jƒdSWqtk rH}|jtjkrI‚qIqXqWdS(s)Wait for child to finish, ignoring EINTR.N(R$twaittOSErrorR R (RtchildR((s,/usr/local/lib/python2.7/test/test_signal.pyR+Cs  cCsGtjtj|jƒtjtj|jƒtjtjtjƒtjtjtjƒt |_ t |_ t j ƒ}tjr‹dG|GHnttjddt|ƒgƒ}|rÛ|j|ƒ|j sÛtjdƒqÛn|j|j ƒ|j|j ƒt |_ ~yItjddt|ƒgƒ}|j|ƒtjdƒ|jdƒWnBtk r”|j|j ƒ|j|j ƒtjr•dGHq•nXttjddt|ƒgƒ}|rÌ|j|ƒny(tjdƒtjƒtjdƒWn?tk rtjrCd GHqCn+|jd tjƒƒnX|jd ƒdS( Nstest runner's pid istkills-HUPis-USR1s#HandlerBCalled exception not raisedsHandlerBCalled exception caughts-USR2s(KeyboardInterrupt (the alarm() went off)s+Some other exception woke us from pause: %ssTpause returned of its own accord, and the signal didn't arrive after another second.( tsignaltSIGHUPR(tSIGUSR1R*tSIGUSR2tSIG_IGNtSIGALRMtdefault_int_handlertFalseR%R)RtgetpidRR&Rt subprocesstPopentstrR+ttimetsleept assertTruet assertFalsetfailRtalarmtpausetKeyboardInterruptR t format_exc(RtpidR-((s,/usr/local/lib/python2.7/test/test_signal.pytrun_testMsT     !        !      tfreebsd6sOinter process signals not reliable (do not mix well with threading) on freebsd6c Csƒtjƒ\}}ttj|ƒƒV}ttj|dƒƒ5}tjƒ}|dkrçz|y_|jƒt|ƒCy|jƒWntjt j ƒ|ƒnXtjd|ƒWdQXWndGHt j ƒnXWdt ƒXn|jƒtj|ggg|jƒ\}}}||krLtj|ƒ} | rs|j| ƒqsn'tj|tjƒ|jd|jƒWdQXWdQXdS(NtwisUh oh, raised from pickle.s!Test deadlocked after %d seconds.(RtpipeRtfdopentforktcloseREtpickletdumpR RCR t print_excR tselectt MAX_DURATIONtloadR?R.R/tSIGKILL( Rt os_done_rt os_done_wtdone_rtdone_wR-trRGtxttb((s,/usr/local/lib/python2.7/test/test_signal.pyt test_mains6       '  N(RRRPRRR R#R(R*R+REtunittesttskipIftsystplatformRZ(((s,/usr/local/lib/python2.7/test/test_signal.pyR's      BtBasicSignalTestscBs,eZd„Zd„Zd„Zd„ZRS(cGsdS(N((RR((s,/usr/local/lib/python2.7/test/test_signal.pyttrivial_signal_handler¿scCs6|jttjdƒ|jttjd|jƒdS(Ni’(t assertRaisest ValueErrorR/t getsignalR`(R((s,/usr/local/lib/python2.7/test/test_signal.pyt,test_out_of_range_signal_number_raises_errorÂscCs |jttjtjdƒdS(N(Rat TypeErrorR/R1R (R((s,/usr/local/lib/python2.7/test/test_signal.pyt0test_setting_signal_handler_to_none_raises_errorÈscCsjtjtj|jƒ}|jtjtjƒ|jƒtjtj|ƒ|jtjtjƒ|ƒdS(N(R/R0R`t assertEqualRc(Rthup((s,/usr/local/lib/python2.7/test/test_signal.pyttest_getsignalÌs  (RRR`RdRfRi(((s,/usr/local/lib/python2.7/test/test_signal.pyR_½s   sWindows specifictWindowsSignalTestscBseZd„ZRS(cCs°d„}xTtjtjtjtjtjtjtjfD]"}tj|tj||ƒƒq:W|jt ƒtjd|ƒWdQX|jt ƒtjd|ƒWdQXdS(NcSsdS(N(R (RXty((s,/usr/local/lib/python2.7/test/test_signal.pytØsiÿÿÿÿi( R/tSIGABRTtSIGBREAKtSIGFPEtSIGILLtSIGINTtSIGSEGVtSIGTERMRaRb(Rthandlertsig((s,/usr/local/lib/python2.7/test/test_signal.pyttest_issue9324Ös  (RRRv(((s,/usr/local/lib/python2.7/test/test_signal.pyRjÔst WakeupFDTestscBseZd„ZRS(cCs&tjƒ}|jttj|ƒdS(N(Rt make_bad_fdRaRbR/t set_wakeup_fd(Rtfd((s,/usr/local/lib/python2.7/test/test_signal.pyttest_invalid_fdès (RRR{(((s,/usr/local/lib/python2.7/test/test_signal.pyRwæstWakeupSignalTestscBs8eZdZdZd„Zd„Zd„Zd„ZRS(i icCs¤ddl}tjdƒtjƒ}tj|jƒtjƒ}|j|||jkƒ|j|jggg|jƒtjƒ}|j|||jkƒdS(Niÿÿÿÿi( ROR/R@R;R<t TIMEOUT_FULLR=t TIMEOUT_HALFtread(RROt before_timetmid_timet after_time((s,/usr/local/lib/python2.7/test/test_signal.pyttest_wakeup_fd_earlyòs     cCszddl}tjdƒtjƒ}|j|j|j|jggg|jƒtjƒ}|j|||j kƒdS(Niÿÿÿÿi( ROR/R@R;RaterrorRR}R=R~(RROR€R‚((s,/usr/local/lib/python2.7/test/test_signal.pyttest_wakeup_fd_durings    cCs™ddl}tjtjd„ƒ|_tjƒ\|_|_|j|j|jdƒ}|tj B}|j|j|j |ƒtj |jƒ|_ dS(NiÿÿÿÿcSsdS(N(R (RXRk((s,/usr/local/lib/python2.7/test/test_signal.pyRlsi( tfcntlR/R4talrmRRHRtwritetF_GETFLt O_NONBLOCKtF_SETFLRyt old_wakeup(RR†tflags((s,/usr/local/lib/python2.7/test/test_signal.pyR s  cCsJtj|jƒtj|jƒtj|jƒtjtj|jƒdS(N( R/RyRŒRRKRRˆR4R‡(R((s,/usr/local/lib/python2.7/test/test_signal.pyRs(RRR}R~RƒR…RR(((s,/usr/local/lib/python2.7/test/test_signal.pyR|ís   tSiginterruptTestcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCsAtj|_tj|jd„ƒ}|jtj|j|ƒdS(s½Install a no-op signal handler that can be set to allow interrupts or not, and arrange for the original signal handler to be re-installed when the test is finished. cSsdS(N(R (RXRk((s,/usr/local/lib/python2.7/test/test_signal.pyRl$sN(R/R1R't addCleanup(Rt oldhandler((s,/usr/local/lib/python2.7/test/test_signal.pyRs cCsøtjƒ\}}|jtj|ƒtjƒ}tjƒ}|dkrˆz1tjdƒtj||j ƒtjdƒWdt ƒXnl|jtj |dƒtj|ƒytj |dƒ}t SWn,tk ró}|jtjkrï‚ntSXdS(s¿Perform a read during which a signal will arrive. Return True if the read is interrupted by the signal and raises an exception. Return False if it returns normally. igš™™™™™É?Ni(RRHRRKR7RJR;R<R.R'R twaitpidRR6R,R R R$(RRWRGtppidRDtdterr((s,/usr/local/lib/python2.7/test/test_signal.pytreadpipe_interrupted's&      cCs6|jƒ}|j|ƒ|jƒ}|j|ƒdS(s¦If a signal handler is installed and siginterrupt is not called at all, when that signal arrives, it interrupts a syscall that's in progress. N(R•R=(Rti((s,/usr/local/lib/python2.7/test/test_signal.pyttest_without_siginterrupt]s   cCsItj|jdƒ|jƒ}|j|ƒ|jƒ}|j|ƒdS(sÅIf a signal handler is installed and siginterrupt is called with a true value for the second argument, when that signal arrives, it interrupts a syscall that's in progress. iN(R/t siginterruptR'R•R=(RR–((s,/usr/local/lib/python2.7/test/test_signal.pyttest_siginterrupt_onhs    cCsItj|jdƒ|jƒ}|j|ƒ|jƒ}|j|ƒdS(sÎIf a signal handler is installed and siginterrupt is called with a false value for the second argument, when that signal arrives, it does not interrupt a syscall that's in progress. iN(R/R˜R'R•R>(RR–((s,/usr/local/lib/python2.7/test/test_signal.pyttest_siginterrupt_offts    (RRRR•R—R™Rš(((s,/usr/local/lib/python2.7/test/test_signal.pyRŽs  6 t ItimerTestcBseZd„Zd„Zd„Zd„Zd„Zd„Zd„Ze j e j d kd ƒd „ƒZ e j e j dkd ƒd „ƒZRS(cCs:t|_d|_d|_tjtj|jƒ|_dS(Ni( R6t hndl_calledt hndl_countR titimerR/R4tsig_alrmt old_alarm(R((s,/usr/local/lib/python2.7/test/test_signal.pyRƒs   cCs?tjtj|jƒ|jdk r;tj|jdƒndS(Ni(R/R4R RžR t setitimer(R((s,/usr/local/lib/python2.7/test/test_signal.pyR‰scGs$t|_tjr d|fGHndS(NsSIGALRM handler invoked(R$RœRR&(RR((s,/usr/local/lib/python2.7/test/test_signal.pyRŸs  cGsŠt|_|jdkr*tjdƒ‚n6|jdkr`tjtjdƒtjr`dGHq`n|jd7_tjr†d|fGHndS(Nis.setitimer didn't disable ITIMER_VIRTUAL timer.islast SIGVTALRM handler callisSIGVTALRM handler invoked( R$RœRR/t ItimerErrorR¡tITIMER_VIRTUALRR&(RR((s,/usr/local/lib/python2.7/test/test_signal.pyt sig_vtalrm”s    cGs7t|_tjtjdƒtjr3d|fGHndS(NisSIGPROF handler invoked(R$RœR/R¡t ITIMER_PROFRR&(RR((s,/usr/local/lib/python2.7/test/test_signal.pytsig_prof¦s  cCs |jtjtjddƒdS(Niÿÿÿÿi(RaR/R¢R¡(R((s,/usr/local/lib/python2.7/test/test_signal.pyttest_itimer_exc­scCsQtj|_tj|jdƒtjr0dGHntjƒ|j|jt ƒdS(Ngð?s call pause()...( R/t ITIMER_REALRžR¡RR&RARgRœR$(R((s,/usr/local/lib/python2.7/test/test_signal.pyttest_itimer_real¶s    RFtnetbsd5sDitimer not reliable (does not mix well with threading) on some BSDs.cCsÏtj|_tjtj|jƒtj|jddƒtjƒ}xUtjƒ|dkrŽtdddƒ}tj|jƒd krGPqGqGW|j dƒ|j tj|jƒd ƒ|j |j t ƒdS( Ng333333Ó?gš™™™™™É?gN@i90i2 i“–˜gs8timeout: likely cause: machine too slow or load too high(gg(gg( R/R£Ržt SIGVTALRMR¤R¡R;tpowt getitimertskipTestRgRœR$(Rt start_timet_((s,/usr/local/lib/python2.7/test/test_signal.pyttest_itimer_virtualÀs   sBitimer not reliable (does not mix well with threading) on freebsd6cCsÏtj|_tjtj|jƒtj|jddƒtjƒ}xUtjƒ|dkrŽtdddƒ}tj|jƒdkrGPqGqGW|j dƒ|j tj|jƒd ƒ|j |j t ƒdS( Ngš™™™™™É?gN@i90i2 i“–˜gs8timeout: likely cause: machine too slow or load too high(gg(gg( R/R¥RžtSIGPROFR¦R¡R;R¬R­R®RgRœR$(RR¯R°((s,/usr/local/lib/python2.7/test/test_signal.pyttest_itimer_prof×s   (sfreebsd6Rª(RRRRRŸR¤R¦R§R©R[R\R]R^R±R³(((s,/usr/local/lib/python2.7/test/test_signal.pyR›s      cCs#tjtttttttƒdS(N( Rt run_unittestR_RRwR|RŽR›Rj(((s,/usr/local/lib/python2.7/test/test_signal.pyRZís t__main__(sos2sriscos(!R[ttestRt contextlibRRRLROR/R8R R]RR;R R^tSkipTestt ExceptionRR RR\tTestCaseRR_t skipUnlessRjRwR|RŽR›RZR(((s,/usr/local/lib/python2.7/test/test_signal.pyts<       0 •-ek