klein icon indicating copy to clipboard operation
klein copied to clipboard

Accessing the `installSignalHandlers` parameter of the `reactor.run()` method

Open Darnethal0z opened this issue 2 years ago • 1 comments

I don't know if it is done on purpose or not, but as it is we cannot access the installSignalHandlers parameter of the reactor.run() method (_app.py, line 681).

An additional parameter implemented in Klein.run() in the same manner as displayTracebacks would be a good addition.

Here is a raw Klein.run() method redefinition from _app.py to explain my point :

def run(
    self,
    host: Optional[str] = None,
    port: Optional[int] = None,
    logFile: Optional[IO] = None,
    endpoint_description: Optional[str] = None,
    displayTracebacks: bool = True,
    installSignalHandlers: bool = True,
) -> None:

    if logFile is None:
        logFile = sys.stdout

    log.startLogging(logFile)

    if not endpoint_description:
        endpoint_description = f"tcp:port={port}:interface={host}"

    endpoint = serverFromString(reactor, endpoint_description)

    site = Site(self.resource())
    site.displayTracebacks = displayTracebacks

    endpoint.listen(site)
    # Passing installSignalHandlers on the method call 
    reactor.run(installSignalHandlers=installSignalHandlers)  # type: ignore[attr-defined]

This is a really small modification, i may provide a proper PR if accepted.

Here is the affiliated Twister documentation page : https://docs.twistedmatrix.com/en/stable/api/twisted.internet.base.ReactorBase.html#run

Darnethal0z avatar Sep 27 '23 15:09 Darnethal0z

Just opened the PR #675

Darnethal0z avatar Sep 28 '23 10:09 Darnethal0z