Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for issue #674 #675

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/examples/disablingsignalhandlerinstallation.rst
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are reasons to want to have this parameter exposed, but … this is not one of them. Twisted logs raised errors automatically already, so this documentation just seems inaccurate? You also don't actually use the logFile parameter here, despite describing it. So this seems like an odd corner of the documentation.

It might be better to document how to call reactor.run or integrate Klein with twisted.internet.task.react directly, rather than copying every possible parameter into the run convenience function.


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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from klein import route, run


@route("/")
def home(request):
return "Hello, world!"


run("localhost", 8080, installSignalHandlers=False)
3 changes: 2 additions & 1 deletion src/klein/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading