U \ @s^ddlZddlmZmZddlmZmZddlmZmZddl m Z eZGdddeZdS)N)ThreadLock)sleeptime)queuecheck_thread_support)loggerc@sbeZdZddZeddZddZddZd d Zd d Z dddZ ddZ ddZ ddZ d S)BackgroundWorkercCs*ttd|_t|_d|_d|_dS)N)rrQueue_queuer_lock_thread_thread_for_pidselfrB/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/worker.py__init__s  zBackgroundWorker.__init__cCs&|jtkrdS|jsdS|jS)NF)rosgetpidris_aliverrrrrs zBackgroundWorker.is_alivecCs|js|dSN)rstartrrrr_ensure_thread$szBackgroundWorker._ensure_threadcCsdt|}|j}|jz8|jrL|t}|dkrt|jdd|_|jd|jt|_ W5QRXdS)Nzraven-sentry.BackgroundWorker)targetnameT) r rr_targetr setDaemonrrrrrrrrr8s  zBackgroundWorker.startc Cs>td|j$|jr0|jtd|_d|_W5QRXdS)Nz"background worker got kill request)rdebugr rr put_nowait _TERMINATORrrrrrkillCs   zBackgroundWorker.killNc CsDtd|j |jr,|dkr,|||W5QRXtddS)Nz#background worker got flush requestgzbackground worker flushed)rr%r r _wait_flush)rrcallbackrrrflushLs  zBackgroundWorker.flushcCsNtd|}||sJ|j}td||dk r<||||||dS)Ng?z%d event(s) pending on flush)minr r Zqsizerr%)rrr*Zinitial_timeoutpendingrrrr)Ts     zBackgroundWorker._wait_flushcCs||j|dSr)rr r&rr*rrrsubmit^szBackgroundWorker.submitcCsf|j}z@|tkrW4qbz |Wn"tk rFtjdddYnXW5|jXtdqdS)NzFailed processing jobT)exc_infor)r getZ task_doner' Exceptionrerrorrr.rrrr#cs   zBackgroundWorker._target)N)__name__ __module__ __qualname__rpropertyrrr rr(r+r)r/r#rrrrr s    r )r threadingrrrrZsentry_sdk._compatrrZsentry_sdk.utilsrr ZAnyOptionalCallableobjectr'r rrrrs