reactor: Move _g_dispatch updating from _dispatch_loop() to run()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2026-03-18 22:40:24 -04:00
committed by KevinOConnor
parent 51ceda9ede
commit 0021798795

View File

@@ -305,7 +305,6 @@ class SelectReactor:
return eventtime
# Main loop
def _dispatch_loop(self):
self._g_dispatch = greenlet.getcurrent()
busy = True
eventtime = self.monotonic()
while self._process:
@@ -318,16 +317,21 @@ class SelectReactor:
hdls = ([(fd, self._READ) for fd in res[0]]
+ [(fd, self._WRITE) for fd in res[1]])
eventtime = self._check_fds(eventtime, hdls)
self._g_dispatch = None
def run(self):
if self._pipe_fds is None:
self._setup_async_callbacks()
self._process = True
self._prevent_pause_count = 0
while self._process:
g_next = ReactorGreenlet(run=self._dispatch_loop)
self._all_greenlets.append(g_next)
g_next.switch()
try:
while self._process:
# Create new greenlet to dispatch timers and events
g_next = ReactorGreenlet(run=self._dispatch_loop)
self._all_greenlets.append(g_next)
self._g_dispatch = g_next
g_next.switch()
# Control returns here on end() request or switch from pause()
finally:
self._g_dispatch = None
def end(self):
self._process = False
def finalize(self):
@@ -368,7 +372,6 @@ class PollReactor(SelectReactor):
self._poll.modify(file_handler.fd, flags)
# Main loop
def _dispatch_loop(self):
self._g_dispatch = greenlet.getcurrent()
busy = True
eventtime = self.monotonic()
while self._process:
@@ -379,7 +382,6 @@ class PollReactor(SelectReactor):
if res:
busy = True
eventtime = self._check_fds(eventtime, res)
self._g_dispatch = None
class EPollReactor(SelectReactor):
def __init__(self, gc_checking=False):
@@ -405,7 +407,6 @@ class EPollReactor(SelectReactor):
self._epoll.modify(file_handler.fd, flags)
# Main loop
def _dispatch_loop(self):
self._g_dispatch = greenlet.getcurrent()
busy = True
eventtime = self.monotonic()
while self._process:
@@ -416,7 +417,6 @@ class EPollReactor(SelectReactor):
if res:
busy = True
eventtime = self._check_fds(eventtime, res)
self._g_dispatch = None
# Use the poll based reactor if it is available
try: