This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Set up file stream for redirecting GC logs
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, penguin_wwy
Priority: normal Keywords: patch

Created on 2021-11-29 15:30 by penguin_wwy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29848 closed penguin_wwy, 2021-11-29 15:33
Messages (6)
msg407286 - (view) Author: penguin_wwy (penguin_wwy) * Date: 2021-11-29 15:30
Set up file stream for redirecting logs by adding a parameter in `set_debug`.

The stderr is used by default.
msg407288 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-29 15:36
Thanks for opening this issue..I think you need to elaborate a bit more about this feature you are suggesting. In general we don't allow this kind of facilities to redirect to file stream anywhere else in the interpreter.
msg407297 - (view) Author: penguin_wwy (penguin_wwy) * Date: 2021-11-29 17:09
Thank you for the reminder.

At first, I wanted to analyze the effectiveness of GC through logs.
However, because GC through the stderr output, these logs are mixed in with other output(such as warnings). This make it difficult to handle them automaticaly.

So, i added an `TestIOWrapper` parameter(Not just file streams, but also other io, sockets, buffer and so on) to `set_debug` function in gcmodule.c, to redirect GC logs.

I think this will help developers monitor the GC more easily, for example when they deal with a memory leak.

Of course, the default will remain the same as the previous behavior , log via stderr :)
msg407298 - (view) Author: penguin_wwy (penguin_wwy) * Date: 2021-11-29 17:15
Sorry, parameter type is `TextIOWrapper`, not `TestIOWrapper`
msg407299 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-29 17:16
There are several problems with this change:

1) The lifetime of the file descriptor. The file descriptor is borrowed, which normally will lead to not being properly cleaned upon failure or interpreter deallocation.

2) The statistics you are trying to fetch via parsing the file are actually available through better APIS:

https://docs.python.org/3/library/gc.html#gc.callbacks
and
https://docs.python.org/3/library/gc.html#gc.get_stats

3) The stderr output is not stable or considered to be stable between releases. The main purpose is to serve as a quick way to debug or check for statistics without using proper callbacks, but enything more involved needs to use the callbacks.

Based on these, I am afraid I don't feel comfortable supporting this patch :(
msg407300 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-29 17:17
There is another problem: PySys_WriteStderr is faster than your gc_log, which can potentially slow down heavy GC-based programs, even if the file descriptor is not used.
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 90086
2021-11-29 17:18:29pablogsalsetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2021-11-29 17:17:59pablogsalsetmessages: + msg407300
2021-11-29 17:16:43pablogsalsetmessages: + msg407299
2021-11-29 17:15:30penguin_wwysetmessages: + msg407298
2021-11-29 17:09:08penguin_wwysetmessages: + msg407297
2021-11-29 15:36:22pablogsalsetnosy: + pablogsal
messages: + msg407288
2021-11-29 15:33:44penguin_wwysetkeywords: + patch
stage: patch review
pull_requests: + pull_request28077
2021-11-29 15:30:48penguin_wwycreate