
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2018-06-27 09:29 bymaggyero, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 33978.patch | xtreak,2018-06-28 07:13 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 8008 | merged | xtreak,2018-06-29 12:36 | |
| PR 8044 | merged | miss-islington,2018-07-02 09:02 | |
| PR 8045 | merged | xtreak,2018-07-02 09:07 | |
| Messages (8) | |||
|---|---|---|---|
| msg320560 -(view) | Author: Géry (maggyero)* | Date: 2018-06-27 09:29 | |
Calling logging.config.dictConfig several times with a file handler in the same Python process leaks resources.INPUT:$ python3 -Wall <<EOFimport logging.configconfig = { "version": 1, "handlers": { "file": { "class": "logging.FileHandler", "filename": "test.log" } }, "root": { "handlers": ["file"] }}logging.config.dictConfig(config)logging.config.dictConfig(config)EOFOUTPUT:/usr/lib/python3.6/logging/config.py:789: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/maggyero/test.log' mode='a' encoding='UTF-8'> self.common_logger_config(root, config, incremental) | |||
| msg320652 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-06-28 07:13 | |
I think while initializing it on the second call we just delete the handlers list variable which contains references to the file handlers instead of properly closing them like it's done in shutdown. handlers is a list of weakreferences and I don't know if they will close file handlers or other resources automatically as they are deleted. If the initialization is done in a loop involving threads then there might be others who are using the handlers as we delete them. The attached patch tries to close the handlers before deletion thus removing the warning. The same is observed in FileConfig too where handlers list is deleted before removal.shutdown method :https://github.com/python/cpython/blob/master/Lib/logging/__init__.py#L1994deletion of handlers before closing them :https://github.com/python/cpython/blob/master/Lib/logging/config.py#L528I think this is merged from Python 2.7 with commithttps://github.com/python/cpython/commit/00ee7baf49430d8a6eed355a5fd7a05179325747 12 years back but doesn't produce any effect on Python 2.7 does -W all or -Wall have any effect ? Thanks | |||
| msg320653 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-06-28 07:19 | |
This seems to be a related issuehttps://bugs.python.org/issue23010 and fix attached but I think it's more towards file handler to be not opened until it's required.Thanks | |||
| msg320856 -(view) | Author: Vinay Sajip (vinay.sajip)*![]() | Date: 2018-07-02 08:57 | |
New changeset087570af6d5d39b51bdd5e660a53903960e58678 by Vinay Sajip (Xtreak) in branch 'master':bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008)https://github.com/python/cpython/commit/087570af6d5d39b51bdd5e660a53903960e58678 | |||
| msg320859 -(view) | Author: Vinay Sajip (vinay.sajip)*![]() | Date: 2018-07-02 09:35 | |
New changeset6f49afc3d983350f4f04d221a26573721f23c475 by Vinay Sajip (Miss Islington (bot)) in branch '3.7':bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008) (GH-8044)https://github.com/python/cpython/commit/6f49afc3d983350f4f04d221a26573721f23c475 | |||
| msg320860 -(view) | Author: Vinay Sajip (vinay.sajip)*![]() | Date: 2018-07-02 09:35 | |
New changesetb6c1989168efeb8b6320bec958e7e339270ac0ce by Vinay Sajip (Xtreak) in branch '3.6':[3.6]bpo-33978: Close existing handlers before logging (re-)configuration. (GH-8008). (GH-8045)https://github.com/python/cpython/commit/b6c1989168efeb8b6320bec958e7e339270ac0ce | |||
| msg320861 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-07-02 09:45 | |
Thanks much @maggyero for the original report and sample test case this was my first non-easy bug fix. Thanks @vinay.sajip for the guidance on logging module implementation.Thanks | |||
| msg320873 -(view) | Author: Géry (maggyero)* | Date: 2018-07-02 11:36 | |
Thanks @xtreak and @vinay.sajip for the fix. | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:02 | admin | set | github: 78159 |
| 2018-07-02 11:36:33 | maggyero | set | messages: +msg320873 |
| 2018-07-02 09:45:45 | xtreak | set | messages: +msg320861 versions: - Python 3.7, Python 3.8 |
| 2018-07-02 09:36:28 | vinay.sajip | set | status: open -> closed stage: patch review -> resolved resolution: fixed versions: + Python 3.7, Python 3.8 |
| 2018-07-02 09:35:54 | vinay.sajip | set | messages: +msg320860 |
| 2018-07-02 09:35:12 | vinay.sajip | set | messages: +msg320859 |
| 2018-07-02 09:07:50 | xtreak | set | pull_requests: +pull_request7654 |
| 2018-07-02 09:02:32 | miss-islington | set | pull_requests: +pull_request7653 |
| 2018-07-02 08:57:53 | vinay.sajip | set | messages: +msg320856 |
| 2018-06-29 12:39:21 | xiang.zhang | set | nosy: +vinay.sajip |
| 2018-06-29 12:36:20 | xtreak | set | stage: patch review pull_requests: +pull_request7613 |
| 2018-06-28 07:19:01 | xtreak | set | messages: +msg320653 |
| 2018-06-28 07:13:24 | xtreak | set | files: +33978.patch nosy: +xtreak messages: +msg320652 keywords: +patch |
| 2018-06-27 09:29:16 | maggyero | create | |