Yf @sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZd gZd Zd ZeeefZ ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&ddde j'ddddddZ(d d!Z)Gd"d#d#ej*Z+Gd$d d ej,Z-dS)%aBase implementation of event loop. The event loop can be broken up into a multiplexer (the part responsible for notifying us of I/O events) and the event loop proper, which wraps a multiplexer with functionality for scheduling callbacks, immediately or at a given time in the future. Whenever a public API takes a callback, subsequent positional arguments will be passed to the callback if/when it is called. This avoids the proliferation of trivial lambdas implementing closures. Keyword arguments for the callback are not supported; this is a conscious design decision, leaving the door open for keyword arguments to modify the meaning of the API call itself. N)compat) coroutines)events)futures)tasks) coroutine)logger BaseEventLoopdg?cCsH|j}tj|r:t|jtjr:t|jSt|SdS)N) Z _callbackinspectZismethod isinstance__self__rTaskreprstr)handlecbr8/opt/alt/python35/lib64/python3.5/asyncio/base_events.py_format_handle:s $ rcCs4|tjkrdS|tjkr&dSt|SdS)Nzz) subprocessPIPESTDOUTr)fdrrr _format_pipeCs rc Cs`ttdstdn>y|jtjtjdWntk r[tdYnXdS)N SO_REUSEPORTz)reuse_port not supported by socket modulerzTreuse_port not supported by socket module, SO_REUSEPORT defined but not implemented.)hasattrsocket ValueError setsockopt SOL_SOCKETrOSError)sockrrr_set_reuseportLs  r$cCs|jtj@tjkS)N)typer SOCK_STREAM)r#rrr_is_stream_socketWsr'cCs|jtj@tjkS)N)r%r SOCK_DGRAM)r#rrr_is_dgram_socket^sr)cCsttdsdS|dtjtjhks:|dkr>dS|tjkrYtj}n|tjkrttj}ndS|dkrd}nwt|tr|dkrd}nSt|tr|dkrd}n/yt |}Wnt t fk rdSYnX|tj krAtj g}ttdrJ|jtjn |g}t|trh|jd}d|krxdSxP|D]H}y-tj|||||d||ffSWqtk rYqXqWdS)N inet_ptonrAF_INET6Zidna%)rrZ IPPROTO_TCPZ IPPROTO_UDPr&r(r bytesrint TypeErrorr AF_UNSPECZAF_INETappendr-decoder*r")hostportfamilyr%protoZafsafrrr _ipaddr_infoesH              r:r7r%r8flagsc Cs|dd\}}t|||||}|dk rZ|j} | j|g| S|j||d|d|d|d|SdS)Nr7r%r8r;)r: create_future set_result getaddrinfo) addressr7r%r8r;loopr5r6infofutrrr_ensure_resolveds  rDcCs=|j}t|tr,t|t r,dS|jjdS)N)Z _exceptionr BaseException Exception_loopstop)rCexcrrr_run_until_complete_cbs  rJc@sjeZdZddZddZddZddZd d Zd d Ze d dZ dS)ServercCs(||_||_d|_g|_dS)Nr)rGsockets _active_count_waiters)selfrArLrrr__init__s   zServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>) __class____name__rL)rOrrr__repr__szServer.__repr__cCs(|jdk st|jd7_dS)Nr)rLAssertionErrorrM)rOrrr_attachszServer._attachcCsP|jdkst|jd8_|jdkrL|jdkrL|jdS)Nrr)rMrTrL_wakeup)rOrrr_detachszServer._detachcCs`|j}|dkrdSd|_x|D]}|jj|q)W|jdkr\|jdS)Nr)rLrGZ _stop_servingrMrV)rOrLr#rrrcloses    z Server.closecCs@|j}d|_x'|D]}|js|j|qWdS)N)rNdoner>)rOwaiterswaiterrrrrVs     zServer._wakeupccsN|jdks|jdkr"dS|jj}|jj||EdHdS)N)rLrNrGr=r3)rOr[rrr wait_closeds zServer.wait_closedN) rR __module__ __qualname__rPrSrUrWrXrVrr\rrrrrKs      rKc@seZdZddZddZddZddZd d Zd d Zd dd dd ddZ d dddd dd dd ddZ d d d ddZ d d ddZ d d ddZ ed ddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zed)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zejrd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPdQdPdRdPdSdPdTdUZ*dPdVdWZ+ed d dXd dOdPdRdPdSdPdYd dZd dd d[d\Z,edd]d^Z-ed d dOdPdRdPdSdPd_d d`d dad dYd dbdcZ.edddeZ/ed d dOe0j1dSe0j2dYd dfdgdXd d_d d`d dhdiZ3edXd djdkZ4edldmZ5edndoZ6dpdqZ7edre8j9dse8j9dte8j9duddvdwdxdPdydzZ:edre8j9dse8j9dte8j9duddvddxdPd{d|Z;d}d~Z<ddZ=ddZ>ddZ?ddZ@ddZAddZBddZCddZDddZEddZFd S)r cCsd|_d|_d|_tj|_g|_d|_d|_d|_ t j dj |_ d|_|jtjj ottjjdd|_d|_d|_d|_ttdrtj|_n d|_d|_dS)NrF monotonicZPYTHONASYNCIODEBUGg?get_asyncgen_hooks) _timer_cancelled_count_closed _stopping collectionsdeque_ready _scheduled_default_executorZ _internal_fds _thread_idtimeZget_clock_infoZ resolution_clock_resolution_exception_handler set_debugsysr;ignore_environmentboolosenvirongetslow_callback_duration_current_handle _task_factory_coroutine_wrapper_setrweakrefWeakSet _asyncgens_asyncgens_shutdown_called)rOrrrrPs(             zBaseEventLoop.__init__cCs,d|jj|j|j|jfS)Nz"<%s running=%s closed=%s debug=%s>)rQrR is_running is_closed get_debug)rOrrrrS szBaseEventLoop.__repr__cCstjd|S)z,Create a Future object attached to the loop.rA)rZFuture)rOrrrr=szBaseEventLoop.create_futurecCsZ|j|jdkrDtj|d|}|jrV|jd=n|j||}|S)zDSchedule a coroutine object. Return a task object. NrAr) _check_closedrvrr_source_traceback)rOcoroZtaskrrr create_tasks   zBaseEventLoop.create_taskcCs2|dk r%t| r%td||_dS)awSet a task factory that will be used by loop.create_task(). If factory is None the default task factory will be set. If factory is a callable, it should have a signature matching '(loop, coro)', where 'loop' will be a reference to the active event loop, 'coro' will be a coroutine object. The callable must return a Future. Nz'task factory must be a callable or None)callabler1rv)rOfactoryrrrset_task_factory#s  zBaseEventLoop.set_task_factorycCs|jS)zs z4BaseEventLoop.shutdown_asyncgens..Zreturn_exceptionsrAmessagez?an error occurred during closing of asynchronous generator {!r} exceptionZasyncgen) r{rzlenlistclearrgatherzipr rFcall_exception_handlerr)rOZ closing_agensZ shutdown_coroZresultsresultrrrrshutdown_asyncgensxs"     z BaseEventLoop.shutdown_asyncgensc Cs|j|jr"tdtjdk r@td|j|jtj|_ |j dk rt j }t j d|jd|jz,tj|x|j|jrPqWWdd|_d|_ tjd|jd|j dk r t j |XdS)zRun until stop() is called.z"This event loop is already runningNz7Cannot run the event loop while another loop is runningZ firstiterZ finalizerF)rr|rrZ_get_running_loop_set_coroutine_wrapper_debug threading get_identrirzrnr`Zset_asyncgen_hooksrrZ_set_running_loop _run_oncerc)rOZold_agen_hooksrrr run_forevers0              zBaseEventLoop.run_forevercCs|jtj| }tj|d|}|r>d|_|jtzIy|jWn4|r|j r|j r|j YnXWd|j tX|j st d|jS)a\Run until the Future is done. If the argument is a coroutine, it is wrapped in a Task. WARNING: It would be disastrous to call run_until_complete() with the same coroutine twice -- it would wrap it in two different Tasks and that can't be good. Return the Future's result, or raise its exception. rAFNz+Event loop stopped before Future completed.)rrZisfuturerZ ensure_futureZ_log_destroy_pendingZadd_done_callbackrJrrYZ cancelledrZremove_done_callbackrr)rOZfutureZnew_taskrrrrun_until_completes       z BaseEventLoop.run_until_completecCs d|_dS)zStop running the event loop. Every callback already scheduled will still run. This simply informs run_forever to stop looping after a complete iteration. TN)rc)rOrrrrHszBaseEventLoop.stopcCs|jrtd|jr%dS|jr>tjd|d|_|jj|jj|j }|dk rd|_ |j dddS)zClose the event loop. This clears the queues and shuts down the executor, but does not wait for the executor to finish. The event loop must not be running. z!Cannot close a running event loopNzClose %rTwaitF) r|rrbrr debugrfrrgrhZshutdown)rOexecutorrrrrXs          zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rb)rOrrrr}szBaseEventLoop.is_closedcCs:|js6tjd|t|js6|jdS)Nzunclosed event loop %r)r}rrrr|rX)rOrrr__del__s  zBaseEventLoop.__del__cCs |jdk S)z*Returns True if the event loop is running.N)ri)rOrrrr|szBaseEventLoop.is_runningcCs tjS)zReturn the time according to the event loop's clock. This is a float expressed in seconds since an epoch, but the epoch, precision, accuracy and drift are unspecified and may differ per event loop. )rjr_)rOrrrrjszBaseEventLoop.timecGs6|j|j|||}|jr2|jd=|S)a8Arrange for a callback to be called at a given time. Return a Handle: an opaque object with a cancel() method that can be used to cancel the call. The delay can be an int or float, expressed in seconds. It is always relative to the current time. Each callback will be called exactly once. If two callbacks are scheduled for exactly the same time, it undefined which will be called first. Any positional arguments after the callback will be passed to the callback when it is called. rr)call_atrjr)rOZdelaycallbackrtimerrrr call_laters  zBaseEventLoop.call_latercGsx|j|jr-|j|j|dtj||||}|jrX|jd=tj|j |d|_ |S)z|Like call_later(), but uses an absolute time. Absolute time corresponds to the event loop's time() method. rrTr) rr _check_thread_check_callbackr TimerHandlerheapqheappushrg)rOwhenrrrrrrr#s      zBaseEventLoop.call_atcGsV|j|jr-|j|j|d|j||}|jrR|jd=|S)aTArrange for a callback to be called as soon as possible. This operates as a FIFO queue: callbacks are called in the order in which they are registered. Each callback will be called exactly once. Any positional arguments after the callback will be passed to the callback when it is called. call_soonrr)rrrr _call_soonr)rOrrrrrrr3s     zBaseEventLoop.call_sooncCs[tj|stj|r3tdj|t|sWtdj||dS)Nz#coroutines cannot be used with {}()z0a callable object was expected by {}(), got {!r})rZ iscoroutineZiscoroutinefunctionr1rr)rOrmethodrrrrFs zBaseEventLoop._check_callbackcCs<tj|||}|jr(|jd=|jj||S)Nrr)rHandlerrfr3)rOrrrrrrrQs   zBaseEventLoop._call_sooncCs>|jdkrdStj}||jkr:tddS)aoCheck that the current thread is the thread running the event loop. Non-thread-safe methods of this class make this assumption and will likely behave incorrectly when the assumption is violated. Should only be called when (self._debug == True). The caller is responsible for checking this condition for performance reasons. NzMNon-thread-safe operation invoked on an event loop other than the current one)rirrr)rOZ thread_idrrrrXs  zBaseEventLoop._check_threadcGsV|j|jr#|j|d|j||}|jrH|jd=|j|S)z"Like call_soon(), but thread-safe.call_soon_threadsaferr)rrrrrr)rOrrrrrrris     z"BaseEventLoop.call_soon_threadsafecGs{|j|jr#|j|d|dkr\|j}|dkr\tjj}||_tj|j||d|S)Nrun_in_executorrA) rrrrh concurrentrZThreadPoolExecutorZ wrap_futureZsubmit)rOrfuncrrrrrts      zBaseEventLoop.run_in_executorcCs ||_dS)N)rh)rOrrrrset_default_executorsz"BaseEventLoop.set_default_executorc Csd||fg}|r*|jd||rA|jd||rX|jd||ro|jd|dj|}tjd||j}tj||||||} |j|} d|| d | f}| |jkrtj|n tj|| S) Nz%s:%rz family=%rztype=%rzproto=%rzflags=%rz, zGet address info %sz(Getting address info %s took %.3f ms: %rg@@) r3joinr rrjrr?rtrB) rOr5r6r7r%r8r;msgt0Zaddrinfodtrrr_getaddrinfo_debugs(  z BaseEventLoop._getaddrinfo_debugr7rr%r8r;c CsW|jr.|jd|j||||||S|jdtj||||||SdS)N)rrrrr?)rOr5r6r7r%r8r;rrrr?s  zBaseEventLoop.getaddrinfocCs|jdtj||S)N)rr getnameinfo)rOZsockaddrr;rrrrszBaseEventLoop.getnameinfosslr# local_addrc#s#| dk r| rtd| dkrI|rI|sCtd|} |dk sa|dk r|dk rytdt||fd|dtjd|d|d |} | g} | dk rt| d|dtjd|d|d |} | j| nd} tj| d |EdH| j}|s:td | dk rd| j}|sdtd g}xU|D]\}}}}}y tjd|d|d|}|j d | dk rax|D]\}}}}}y|j |PWqtk rI}z9t|j d j ||j j}|j|WYdd}~XqXqW|jd}wq|jr}tjd |||j||EdHWnhtk r}z(|dk r|j|j|WYdd}~Xqq|dk r|jYqqXPqqWt|dkr"|dqt|dtfdd|Dr[|dtdj djdd|Dn9|dkrtdt|stdj ||j|||| EdH\}}|jr|jd}tjd|||||||fS)aConnect to a TCP server. Create a streaming transport connection to a given Internet host and port: socket family AF_INET or socket.AF_INET6 depending on host (or family if specified), socket type SOCK_STREAM. protocol_factory must be a callable returning a protocol instance. This method is a coroutine which will try to establish the connection in the background. When successful, the coroutine returns a (transport, protocol) pair. Nz+server_hostname is only meaningful with sslz:You must set server_hostname when using ssl without a hostz8host/port and sock can not be specified at the same timer7r%r8r;rAz!getaddrinfo() returned empty listFz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s!|]}t|kVqdS)N)r)rrI)modelrr sz2BaseEventLoop.create_connection..zMultiple exceptions: {}z, css|]}t|VqdS)N)r)rrIrrrrsz5host and port was not specified and no sock specifiedz&A Stream Socket was expected, got {!r}rz%r connected to %s:%r: (%r, %r))rrDrr&r3rrrr" setblockingbinderrnorstrerrorlowerrXrr r sock_connectrrallrr'_create_connection_transportget_extra_info)rOprotocol_factoryr5r6rr7r8r;r#rrf1fsf2infosZ laddr_infos exceptionsr%Zcnamer@_ZladdrrI transportrr)rrcreate_connections                $         %     zBaseEventLoop.create_connectionc cs|jd|}|j}|rjt|tr=dn|}|j||||d|d|} n|j|||} y |EdHWn| jYnX| |fS)NFrr)rr=r rprrrX) rOr#rrrrrr[rrrrrr+s     z*BaseEventLoop._create_connection_transport reuse_address reuse_portallow_broadcastc#s| dk rt| s-tdj| s]s]|s]|s]|s]|s]|s]| rtddd|d|d|d|d |d | } d jd d | jD} tdj| | jdd} nps|dkrtd||fdff}n<tj}xdfdffD]\}}|dk rDt |t r}t |dkst dt |d|dtjd|d|d|EdH}|stdxS|D]K\}}}}}||f}||krddg||<||||.zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrr<z2-tuple is expectedr%rAz!getaddrinfo() returned empty listcsNg|]D\}}r(|ddkp;o;|ddks||fqS)rNrr)rkeyZ addr_pair)rrrrrxs z:BaseEventLoop.create_datagram_endpoint..zcan not get address informationposixcygwinz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)$r)rrdictritemsrrd OrderedDictr tuplerrTrDrr(r"rqnamernplatformr r! SO_REUSEADDRr$Z SO_BROADCASTrrrXr3r=rrr rBr)rOrrrr7r8r;rrrr#ZoptsZproblemsZr_addrZaddr_pairs_infoZ addr_infosidxZaddrrZfamrZpror@rrZ local_addressZremote_addressrIrr[rr)rrrcreate_datagram_endpointCs            % $    "                    z&BaseEventLoop.create_datagram_endpointc csQt||fd|dtjd|d|EdH}|sMtdj||S)Nr7r%r;rAz%getaddrinfo({!r}) returned empty list)rDrr&r"r)rOr5r6r7r;rrrr_create_server_getaddrinfos  z(BaseEventLoop._create_server_getaddrinfobacklogr c #sdt|trtd|dk s3dk r|dk rKtdttdd} | dkrtjdkotj dk} g} |dkrdg} n4t|t st|t j  r|g} n|} fd d | D}t j|d EdH}ttjj|}d }zWxJ|D]B}|\}}}}}ytj|||}Wn=tjk rjrtjd |||ddw=YnX| j|| r|jtjtjd| rt||| kr!ttdr!|jtjtjdy|j|Wq=t k r~}z*t |j!d||j"j#fWYdd}~Xq=Xq=Wd}Wd|sx| D]}|j$qWXnB|dkrtdt%|stdj&||g} t'| }xA| D]9}|j(||j)d j*|||||q Wjr`tj+d||S)a1Create a TCP server. The host parameter can be a string, in that case the TCP server is bound to host and port. The host parameter can also be a sequence of strings and in that case the TCP server is bound to all hosts of the sequence. If a host appears multiple times (possibly indirectly e.g. when hostnames resolve to the same IP address), the server is only bound once to that host. Return a Server object which can be used to stop the service. This method is a coroutine. z*ssl argument must be an SSLContext or NoneNz8host/port and sock can not be specified at the same timer-rrrr,c s.g|]$}j|ddqS)r7r;)r)rr5)r7r;r6rOrrrs z/BaseEventLoop.create_server..rAFz:create_server() failed to create socket.socket(%r, %r, %r)exc_infoT IPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedz&A Stream Socket was expected, got {!r}z %r is serving),r rpr1rgetattrrrqrrnrrrdIterablerrset itertoolschain from_iterableerrorrr warningr3r r!rr$rrZ IPV6_V6ONLYrr"rrrrXr'rrKZlistenrZ_start_servingrB)rOrr5r6r7r;r#rrrrr-rLZhostsrrZ completedresr9Zsocktyper8Z canonnameZsaerrrr)r7r;r6rOr create_servers               0          zBaseEventLoop.create_serverccst|s!tdj||j|||dddEdH\}}|jrx|jd}tjd|||||fS)aHandle an accepted connection. This is used by servers that accept connections outside of asyncio but that use asyncio to handle connections. This method is a coroutine. When completed, the coroutine returns a (transport, protocol) pair. z&A Stream Socket was expected, got {!r}r,rTNrz%r handled: (%r, %r))r'rrrrrr r)rOrr#rrrrrrconnect_accepted_socket.s # z%BaseEventLoop.connect_accepted_socketc cs~|}|j}|j|||}y |EdHWn|jYnX|jrttjd|j||||fS)Nz Read pipe %r connected: (%r, %r))r=rrXrr rfileno)rOrrrr[rrrrconnect_read_pipeEs      zBaseEventLoop.connect_read_pipec cs~|}|j}|j|||}y |EdHWn|jYnX|jrttjd|j||||fS)Nz!Write pipe %r connected: (%r, %r))r=rrXrr rr)rOrrrr[rrrrconnect_write_pipeVs      z BaseEventLoop.connect_write_pipecCs|g}|dk r,|jdt||dk ra|tjkra|jdt|nF|dk r|jdt||dk r|jdt|tjdj|dS)Nzstdin=%szstdout=stderr=%sz stdout=%sz stderr=%s )r3rrrr rr)rOrrrrrBrrr_log_subprocessgs    zBaseEventLoop._log_subprocessrrruniversal_newlinesrTrc kst|ttfs!td|r3td|sEtd|dkr]td|} |jrd|} |j| ||||j| |d||||| EdH} |jrtjd| | | | fS) Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r) r r/rrrrrr rB) rOrcmdrrrrrrrr debug_logrrrrsubprocess_shellts"        # zBaseEventLoop.subprocess_shellc os |rtd|r$td|dkr<td|f| } x<| D]4} t| ttfsPtdt| jqPW|} |jrd|}|j|||||j | | d||||| EdH}|jrt j d|||| fS) Nz universal_newlines must be Falsezshell must be Falserzbufsize must be 0z8program arguments must be a bytes or text string, not %szexecute program %rFz%s: %r) rr rr/r1r%rRrrrr rB)rOrZprogramrrrrrrrrZ popen_argsargrrrrrrsubprocess_execs*          zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )rl)rOrrrget_exception_handlersz#BaseEventLoop.get_exception_handlercCs;|dk r.t| r.tdj|||_dS)aSet handler as the new event loop exception handler. If handler is None, the default exception handler will be set. If handler is a callable object, it should have a signature matching '(loop, context)', where 'loop' will be a reference to the active event loop, 'context' will be a dict object (see `call_exception_handler()` documentation for details about context). Nz/A callable object or None is expected, got {!r})rr1rrl)rOZhandlerrrrset_exception_handlers   z#BaseEventLoop.set_exception_handlerc Cs|jd}|sd}|jd}|dk rQt|||jf}nd}d|kr|jdk r|jjr|jj|d<|g}xt|D]}|dkrq||}|dkrdjtj|}d }||j 7}nI|dkr=djtj|}d }||j 7}n t |}|j d j ||qWt jd j|d |dS)a@Default exception handler. This is called when an exception occurs and no exception handler is set, and can be called by a custom exception handler that wants to defer to the default behavior. The context parameter has the same meaning as in `call_exception_handler()`. rz!Unhandled exception in event looprNFZsource_tracebackZhandle_tracebackr,z+Object created at (most recent call last): z+Handle created at (most recent call last): z{}: {} r>rr)rsr% __traceback__rursortedr traceback format_listrstriprr3rr r) rOcontextrrrZ log_linesrvaluetbrrrdefault_exception_handlers6          z'BaseEventLoop.default_exception_handlercCs|jdkrKy|j|Wqtk rGtjdddYqXny|j||Wnptk r}zPy#|jddd|d|iWn%tk rtjd ddYnXWYdd}~XnXdS) aCall the current event loop's exception handler. The context argument is a dict containing the following keys: - 'message': Error message; - 'exception' (optional): Exception object; - 'future' (optional): Future instance; - 'handle' (optional): Handle instance; - 'protocol' (optional): Protocol instance; - 'transport' (optional): Transport instance; - 'socket' (optional): Socket instance; - 'asyncgen' (optional): Asynchronous generator that caused the exception. New keys maybe introduced in the future. Note: do not overload this method in an event loop subclass. For custom exception handling, use the `set_exception_handler()` method. Nz&Exception in default exception handlerrTrz$Unhandled error in exception handlerrr'zeException in default exception handler while handling an unexpected error in custom exception handler)rlr*rFr r)rOr'rIrrrrs"    z$BaseEventLoop.call_exception_handlercCsXt|tjstd|jr+dSt|tj sDt|jj|dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)r rrrT _cancelledrrfr3)rOrrrr _add_callbacks  zBaseEventLoop._add_callbackcCs|j||jdS)z6Like _add_callback() but called from a signal handler.N)r,r)rOrrrr_add_callback_signalsafe's z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rgra)rOrrrr_timer_handle_cancelled,s z%BaseEventLoop._timer_handle_cancelledc Cslt|j}|tkr|j|tkrg}x3|jD](}|jrYd|_q>|j|q>Wtj|||_d|_nJxG|jr|jdjr|jd8_tj |j}d|_qWd}|j s|j rd}n2|jr)|jdj }t d||j}|jr|dkr|j}|jj|}|j|}|dkrtj} n tj} t|} |dkrtj| d|d| q+| rtj| d|d|d| q+|dkr+tj| d |d|dn|jj|}|j||j|j} xU|jr|jd}|j | krtPtj |j}d|_|j j|qNWt|j } xt| D]} |j j}|jrq|jrTz[||_|j}|j|j|}||jkrCtjd t||Wdd|_Xq|jqWd}dS) zRun one full iteration of the event loop. This calls all currently ready callbacks, polls for I/O, schedules the resulting callbacks, and finally schedules 'call_later' callbacks. FrrNg?zpoll took %.3f ms: %s eventsg@@z$poll %.3f ms took %.3f ms: %s eventsz"poll %.3f ms took %.3f ms: timeoutzExecuting %s took %.3f seconds) rrg_MIN_SCHEDULED_TIMER_HANDLESra%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr+r3rheapifyheappoprfrcZ_whenmaxrjrZ _selectorZselectloggingINFODEBUGr logrrkrangepopleftruZ_runrtrr)rOZ sched_countZ new_scheduledrZtimeoutrrrrlevelZneventZend_timeZntodoirrrr1s                                zBaseEventLoop._run_oncec Csytj}tj}Wntk r.dSYnXt|}|j|krNdStj}|}|r|d|fkrtj d|t q||d|_n<|d|fkrtj d|t n|dd|_dS)Nz[loop.set_debug(True): cannot set debug coroutine wrapper; another wrapper is already set %rTzWloop.set_debug(False): cannot unset debug coroutine wrapper; another wrapper was set %rF) rnset_coroutine_wrapperget_coroutine_wrapperAttributeErrorrprwrZ debug_wrapperrrRuntimeWarning)rOenabledZ set_wrapperZ get_wrapperwrapperZcurrent_wrapperrrrrs.          z$BaseEventLoop._set_coroutine_wrappercCs|jS)N)r)rOrrrr~szBaseEventLoop.get_debugcCs&||_|jr"|j|dS)N)rr|r)rOr@rrrrms  zBaseEventLoop.set_debug)GrRr]r^rPrSr=rrrrrrrrrrrrrrrrrrrHrXr}rZPY34rr|rjrrrrrrrrrrr?rrrrrrr2Z AI_PASSIVErrrrrrrrrrr r*rr,r-r.rrr~rmrrrrr s  !            %             !   u    _     , 2    c ! ).__doc__rdZconcurrent.futuresrrr r r4rqrrrrjr$rnrrxr,rrrrrrr7r __all__r/r0BrokenPipeErrorConnectionResetErrorConnectionAbortedErrorZ_FATAL_ERROR_IGNORErrr$r'r)r:r&rDrJZAbstractServerrKZAbstractEventLoopr rrrrsL                    = /