Skip to content

Commit

Permalink
remove unnecessary selectreactor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph committed Nov 2, 2022
1 parent 22c0d8d commit e92e152
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 48 deletions.
48 changes: 1 addition & 47 deletions src/twisted/internet/_glibbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from zope.interface import implementer

from twisted.internet import base, posixbase, selectreactor
from twisted.internet import base, posixbase
from twisted.internet.abstract import FileDescriptor
from twisted.internet.interfaces import IReactorFDSet, IReadDescriptor, IWriteDescriptor
from twisted.python import log
Expand Down Expand Up @@ -309,49 +309,3 @@ def _simulate(self):
"""
self.runUntilCurrent()
self._reschedule()


class PortableGlibReactorBase(selectreactor.SelectReactor):
"""
Base class for GObject event loop reactors that works on Windows.
Sockets aren't supported by GObject's input_add on Win32.
"""

def __init__(self, glib_module: Any, gtk_module: Any, useGtk: bool = False) -> None:
self._simtag = None
self._glib = glib_module
selectreactor.SelectReactor.__init__(self)

self._source_remove = self._glib.source_remove
self._timeout_add = self._glib.timeout_add

self.loop = self._glib.MainLoop()
self._crash = _loopQuitter(self._glib.idle_add, self.loop.quit)
self._run = self.loop.run

def crash(self):
selectreactor.SelectReactor.crash(self)
self._crash()

def run(self, installSignalHandlers=True):
self.startRunning(installSignalHandlers=installSignalHandlers)
self._timeout_add(0, self.simulate)
if self._started:
self._run()

def simulate(self):
"""
Run simulation loops and reschedule callbacks.
"""
if self._simtag is not None:
self._source_remove(self._simtag)
self.iterate()
timeout = self.timeout()
if timeout is None or timeout > 0.01:
timeout = 0.01
self._simtag = self._timeout_add(
int(timeout * 1000),
self.simulate,
priority=self._glib.PRIORITY_DEFAULT_IDLE,
)
3 changes: 2 additions & 1 deletion src/twisted/internet/gireactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run():
self._crash = app.quit


class PortableGIReactor(_glibbase.PortableGlibReactorBase):
class PortableGIReactor(_glibbase.GlibReactorBase):
"""
Portable GObject Introspection event loop reactor.
"""
Expand All @@ -114,6 +114,7 @@ def install(useGtk: bool = False) -> Union[GIReactor, PortableGIReactor]:
@param useGtk: A hint that the Gtk GUI will or will not be used. Currently
does not modify any behavior.
"""
reactor: Union[GIReactor, PortableGIReactor]
if runtime.platform.getType() == "posix":
reactor = GIReactor(useGtk=useGtk)
else:
Expand Down

0 comments on commit e92e152

Please sign in to comment.