From a59c88118a004b8f0caef3e74236a8100ab508e6 Mon Sep 17 00:00:00 2001 From: Darnethal0z <118600108+Darnethal0z@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:06:27 +0200 Subject: [PATCH 1/4] Added `installSignalHandlers` parameter on `klein.run()` --- src/klein/_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/klein/_app.py b/src/klein/_app.py index 5459ac5da..a608e0fed 100644 --- a/src/klein/_app.py +++ b/src/klein/_app.py @@ -639,6 +639,7 @@ def run( logFile: Optional[IO] = None, endpoint_description: Optional[str] = None, displayTracebacks: bool = True, + installSignalHandlers: bool = True, ) -> None: """ Run a minimal twisted.web server on the specified C{port}, bound to the @@ -678,7 +679,7 @@ def run( site.displayTracebacks = displayTracebacks endpoint.listen(site) - reactor.run() # type: ignore[attr-defined] + reactor.run(installSignalHandlers=installSignalHandlers) # type: ignore[attr-defined] _globalKleinApp = Klein() From 9a2b72bb1f43e00003a7633ef7ac2d64a4b0e312 Mon Sep 17 00:00:00 2001 From: Darnethal0z <118600108+Darnethal0z@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:17:03 +0200 Subject: [PATCH 2/4] Adding example --- .../disablingsignalhandlerinstallation.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/examples/disablingsignalhandlerinstallation.rst diff --git a/docs/examples/disablingsignalhandlerinstallation.rst b/docs/examples/disablingsignalhandlerinstallation.rst new file mode 100644 index 000000000..eab56f7fd --- /dev/null +++ b/docs/examples/disablingsignalhandlerinstallation.rst @@ -0,0 +1,22 @@ +================================================ +Example -- Disabling signal handler installation +================================================ + +You have the possibility to print raised errors directly in the file descriptor specified in the ``Klein.run()`` ``logFile`` parameter, it can be useful for troubleshooting or logging fins. + +Below is an example of such implementation, the raised errors will be printed in ``sys.stdout`` by default : + + +.. code-block:: python + + from klein import route, run + + + @route("/") + def home(request): + return "Hello, world!" + + + run("localhost", 8080, installSignalHandlers=False) + +This is an addition of the ``Klein.handle_errors`` method. \ No newline at end of file From adf0a10fb92061dcaaa4a8eb80f47b5541033a18 Mon Sep 17 00:00:00 2001 From: Darnethal0z <118600108+Darnethal0z@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:19:02 +0200 Subject: [PATCH 3/4] Added code example for `Klein.run()` `installSignalHandlers` parameter usage --- .../codeexamples/helloWorldNoSignalInstallation.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/introduction/codeexamples/helloWorldNoSignalInstallation.py diff --git a/docs/introduction/codeexamples/helloWorldNoSignalInstallation.py b/docs/introduction/codeexamples/helloWorldNoSignalInstallation.py new file mode 100644 index 000000000..5075695db --- /dev/null +++ b/docs/introduction/codeexamples/helloWorldNoSignalInstallation.py @@ -0,0 +1,9 @@ +from klein import route, run + + +@route("/") +def home(request): + return "Hello, world!" + + +run("localhost", 8080, installSignalHandlers=False) From 78ae117e71e77a0f2f3d2b1859eff4510e6a2e14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 10:20:45 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/examples/disablingsignalhandlerinstallation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/disablingsignalhandlerinstallation.rst b/docs/examples/disablingsignalhandlerinstallation.rst index eab56f7fd..d4ad8484b 100644 --- a/docs/examples/disablingsignalhandlerinstallation.rst +++ b/docs/examples/disablingsignalhandlerinstallation.rst @@ -4,7 +4,7 @@ Example -- Disabling signal handler installation You have the possibility to print raised errors directly in the file descriptor specified in the ``Klein.run()`` ``logFile`` parameter, it can be useful for troubleshooting or logging fins. -Below is an example of such implementation, the raised errors will be printed in ``sys.stdout`` by default : +Below is an example of such implementation, the raised errors will be printed in ``sys.stdout`` by default : .. code-block:: python @@ -19,4 +19,4 @@ Below is an example of such implementation, the raised errors will be printed in run("localhost", 8080, installSignalHandlers=False) -This is an addition of the ``Klein.handle_errors`` method. \ No newline at end of file +This is an addition of the ``Klein.handle_errors`` method.