-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
asyncio docs should call out that network logging is a no-no #65046
Comments
The asyncio package uses the logging module. We should remind users that they should always configure their logs to go to a file on the local filesystem -- using any kind of network logging will block the event loop. |
Can we instead re-engineer asyncio logging to have logger calls in a separate thread? I.e. |
If you really need network logging you should be able to configure a handler that puts things in a queue whose other end is serviced by an asyncio task. There should be no need to mess with the type of the logger object. Anyway, in 3.4 it is what it is. :-) |
It's something that is easy to misconfigure. Having [logger+queue+logging thread] combination mitigates the risk a bit, but yeah, at the cost of increased complexity...
Right. |
Hi, |
+Logs for :mod:`asyncio` module should always point to a file on the local Well... even writing to a local file can block :-/ By "network", what about the local UNIX socket used by syslog? I guess that the safest option would be a new asyncio library running |
Typical network logging is using syslog UDP. Sending UDP is never block. |
As of #65046 (comment), is this fixed or still work left todo ? This is the oldest asyncio open. |
@Mariatta I can't find any page about asyncio or logging that has the phrase "should always point to a file on the local filesystem". You never mentioned a PR. Do you recall whether that was landed, and in which file? |
The change was attached as a patch: https://bugs.python.org/file45182/issue20847.patch diff -r 4b6e6a77e501 Doc/library/asyncio-dev.rst
--- a/Doc/library/asyncio-dev.rst Sat Oct 22 03:21:55 2016 +0000
+++ b/Doc/library/asyncio-dev.rst Fri Oct 21 22:23:14 2016 -0700
@@ -169,6 +169,8 @@
logging.getLogger('asyncio').setLevel(logging.WARNING)
+Logs for :mod:`asyncio` module should always point to a file on the local
+filesystem. Using any kind of network logging will block the event loop.
.. _asyncio-coroutine-not-scheduled:
|
Whoops! @kumaraditya303 Do you want to create a patch? We can add |
See #97559. Local files can also block so it should not be done in same thread so it isn't 100% correct. |
Explain that logging should not use network I/O. (cherry picked from commit d68c37c) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Explain that logging should not use network I/O. (cherry picked from commit d68c37c) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Hm, I think we should reopen this because I was too fast in merging the PR. @merwok had some reasonable concerns. |
To keep the discussion here, here is the change committed:
My remark:
Guido:
|
OK, then it’s enough that the doc mention
Ah true, the doc page is logging-dev, not regular user tutorial.
Now I am confused: this doc is not for users (python developers using logging, not someone writing a logging handler, although there can be overlap), but users should heed the warning? (Maybe it’s just me — I’ll wait to see if kumaraditya303 understands your meaning better than I!) |
Do I understand my own meaning? I'm not sure. :-( This page is a separate section of the asyncio library docs titled "Developing with asyncio" and appears to be guidance for users who are learning to use asyncio, focusing on common things you might do out of habit that aren't a good idea. So I think this doc is for users. And the paragraph added is in a section titled "Logging" which (until this PR) just shows how to adjust the logging level for the logger used by asyncio itself. From this perspective I think the only questionable part is the recommendation to use non-blocking I/O, which would lead people to believe they should write a logger that uses the event loop, which is likely to lead to more confusion when asyncio is logging things. (Especially since sometimes the logging happens from code run in another thread, like getaddrinfo.) And yes, it is terse and vague, like some other advice in this section. |
@vsajip could you look at the PR and say if the new line of info is good enough? |
Well, it's probably too brief to be useful to all users. IMO it would be more useful to more people to have a logging cookbook recipe showing how to do logging from async code without blocking the event loop, and then referring to that recipe in this bit. I'm not sure my |
I'll happily review it. I'm not sure what we should suggest though. Logging to a file should be fine, but if you really want network logging, you cannot use the asyncio loop at all, since some asyncio logging is called from inside loop internals when the loop is not necessarily in a usable, consistent state. So the alternative would be to have a separate helper thread that runs the network logging, and have the logger used by asyncio just put the processed log record in a queue that is read by the helper thread -- and hope that the helper thread can keep up. This seems rather advanced material for the document we're discussing -- maybe it should just state "don't configure network logging for the asyncio logger". Or maybe the recipe could be in the logging cookbook and the asyncio-dev text can link to that. |
There's already a recipe in the logging cookbook under the section Dealing with handlers that block. It uses a |
Proposed additional note:
|
Yeah, adding that note to tha cookbook recipe seems like a good start. I agree that asyncio itself shouldn't mess with this (and the default logging goes to stderr IIRC, which seems fine). We should then also link to the cookbook recipe from the asyncio docs where this started (and maybe remove the "or use non-blocking I/O" part). |
(cherry picked from commit 5c110d1) Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
(cherry picked from commit 5c110d1) Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
* main: (38 commits) pythongh-98251: Allow venv to pass along PYTHON* variables to pip and ensurepip when they do not impact path resolution (pythonGH-98259) Bpo-41246: IOCP Proactor avoid callback code duplication (python#21399) bpo-46364: Use sockets for stdin of asyncio only on AIX (python#30596) pythongh-98178: syslog() is not thread-safe on macOS (python#98213) Mark all targets in `Doc/Makefile` as `PHONY` (pythonGH-98189) pythongh-97982: Factorize PyUnicode_Count() and unicode_count() code (python#98025) pythongh-96265: Formatting changes for faq/general (python#98129) tutorial: remove "with single quotes" (python#98204) pythongh-97669: Remove Tools/scripts/startuptime.py (python#98214) signalmodule.c uses _PyErr_WriteUnraisableMsg() (python#98217) pythongh-97669: Fix test_tools reference leak (python#98216) pythongh-97669: Create Tools/patchcheck/ directory (python#98186) pythongh-65046: Link to logging cookbook from asyncio docs (python#98207) Formatting fixes in contextlib docs (python#98111) pythongh-95276: Add callable entry to the glossary (python#95738) pythongh-96130: Rephrase use of "typecheck" verb for clarity (python#98144) Fix some incorrect indentation around the main switch (python#98177) pythongh-98172: Fix formatting in `except*` docs (python#98173) pythongh-97982: Remove asciilib_count() (python#98164) pythongh-95756: Free and NULL-out code caches when needed (pythonGH-98181) ...
* main: (37 commits) pythongh-98251: Allow venv to pass along PYTHON* variables to pip and ensurepip when they do not impact path resolution (pythonGH-98259) Bpo-41246: IOCP Proactor avoid callback code duplication (python#21399) bpo-46364: Use sockets for stdin of asyncio only on AIX (python#30596) pythongh-98178: syslog() is not thread-safe on macOS (python#98213) Mark all targets in `Doc/Makefile` as `PHONY` (pythonGH-98189) pythongh-97982: Factorize PyUnicode_Count() and unicode_count() code (python#98025) pythongh-96265: Formatting changes for faq/general (python#98129) tutorial: remove "with single quotes" (python#98204) pythongh-97669: Remove Tools/scripts/startuptime.py (python#98214) signalmodule.c uses _PyErr_WriteUnraisableMsg() (python#98217) pythongh-97669: Fix test_tools reference leak (python#98216) pythongh-97669: Create Tools/patchcheck/ directory (python#98186) pythongh-65046: Link to logging cookbook from asyncio docs (python#98207) Formatting fixes in contextlib docs (python#98111) pythongh-95276: Add callable entry to the glossary (python#95738) pythongh-96130: Rephrase use of "typecheck" verb for clarity (python#98144) Fix some incorrect indentation around the main switch (python#98177) pythongh-98172: Fix formatting in `except*` docs (python#98173) pythongh-97982: Remove asciilib_count() (python#98164) pythongh-95756: Free and NULL-out code caches when needed (pythonGH-98181) ...
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: