U vâ’ia ã@sŠddlZddlmZmZmZddlmZddlmZddl m Z ddl m Z e  d¡ZGd d „d e ƒZGd d „d eƒZGd d„deƒZdS)éN)ÚThreadÚcurrent_threadÚlocal)ÚMutableMapping)ÚWeakKeyDictionaryé)Ú Trampoline)ÚTrampolineSchedulerZRxc@s^eZdZUdZeƒZeeeedffe d<e ddœdd„ƒZ ddœdd„Z e dœd d „ZdS) ÚCurrentThreadScheduleraÉRepresents an object that schedules units of work on the current thread. You should never schedule timeouts using the *CurrentThreadScheduler*, as that will block the thread while waiting. Each instance manages a number of trampolines (and queues), one for each thread that calls a *schedule* method. These trampolines are automatically garbage-collected when threads disappear, because they're stored in a weak key dictionary. Ú_global©ÚreturncCsdtƒ}tj |¡}|dkr,tƒ}|tj|<n|}z ||}Wn"tk r^tƒ}|||<YnX|S)aE Obtain a singleton instance for the current thread. Please note, if you pass this instance to another thread, it will effectively behave as if it were created by that other thread (separate trampoline and queue). Returns: The singleton *CurrentThreadScheduler* instance. N)rr r ÚgetrÚKeyErrorÚCurrentThreadSchedulerSingleton)ÚclsÚthreadZ class_mapZ class_map_Úself©rú[/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/currentthreadscheduler.pyÚ singletons  ÿ  z CurrentThreadScheduler.singletonNcCs tƒ|_dS©N)rÚ_tramps©rrrrÚ__init__6szCurrentThreadScheduler.__init__cCs.tƒ}|j |¡}|dkr*tƒ}||j|<|Sr)rrrr)rrÚtramprrrÚget_trampoline9s   z%CurrentThreadScheduler.get_trampoline)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr rÚtyperÚ__annotations__Ú classmethodrrrrrrrrr s  ÿr cs"eZdZddœ‡fdd„ Z‡ZS)Ú_LocalNr cstƒ ¡tƒ|_dSr)Úsuperrrrr©Ú __class__rrrCs z_Local.__init__)rrrrÚ __classcell__rrr&rr$Bsr$c@s.eZdZeƒZddœdd„Zedœdd„ZdS)rNr cCsdSrrrrrrrMsz(CurrentThreadSchedulerSingleton.__init__cCstjjSr)rÚ_localrrrrrrPsz.CurrentThreadSchedulerSingleton.get_trampoline)rrrr$r)rrrrrrrrHsr)ÚloggingÚ threadingrrrÚtypingrÚweakrefrZ trampolinerZtrampolineschedulerr Ú getLoggerÚlogr r$rrrrrÚs     6