Skip to content

Commit

Permalink
Don't instantiate new CurrentThreadScheduler._Local with each schedul…
Browse files Browse the repository at this point in the history
…er instance
  • Loading branch information
erikkemperman committed May 4, 2019
1 parent b0d75e4 commit a72bafe
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions rx/concurrency/currentthreadscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CurrentThreadScheduler(SchedulerBase):
that will block the current thread while waiting.
"""

_local = _Local()
_global: MutableMapping[threading.Thread, 'CurrentThreadScheduler'] = WeakKeyDictionary()

def __new__(cls) -> 'CurrentThreadScheduler':
Expand All @@ -62,9 +63,7 @@ def __new__(cls) -> 'CurrentThreadScheduler':
def __init__(self) -> None:
"""Creates a scheduler that schedules work as soon as possible
on the current thread."""

super().__init__()
self._local = _Local()

def schedule(self,
action: typing.ScheduledAction,
Expand Down Expand Up @@ -127,7 +126,7 @@ def schedule_absolute(self,

si: ScheduledItem[typing.TState] = ScheduledItem(self, state, action, duetime)

local: _Local = self._local
local: _Local = CurrentThreadScheduler._local
local.queue.enqueue(si)
if local.idle:
local.idle = False
Expand All @@ -147,7 +146,7 @@ def schedule_required(self) -> bool:
False; otherwise, if the trampoline is not active, then it
returns True.
"""
return self._local.idle
return CurrentThreadScheduler._local.idle

def ensure_trampoline(self, action):
"""Method for testing the CurrentThreadScheduler."""
Expand Down

0 comments on commit a72bafe

Please sign in to comment.