-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-111726: Explicitly close database connections in sqlite3 doctests #111730
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
Conversation
There are still some left:
|
One more thing: when running locally I got these files in my
|
Yeah, we don't clean up temporary files in the doctests. We should, though. |
@erlend-aasland do you have any idea why do we still have ResourceWarnings? I've looked through the code multiple times, but I cannot find leaking resources. It is a shame that we cannot debug it :( |
I'll have a look tomorrow. |
Ok, looks like I understood the problem. Here's the sample code that does this (it is in >>> sqlite3.enable_callback_tracebacks(True)
>>> con = sqlite3.connect(":memory:")
>>> def evil_trace(stmt):
... 5/0
...
>>> con.set_trace_callback(evil_trace)
>>> def debug(unraisable):
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
... print(f"Error message: {unraisable.err_msg}")
>>> import sys
>>> sys.unraisablehook = debug
>>> cur = con.execute("SELECT 1")
ZeroDivisionError('division by zero') in callback evil_trace
Error message: None |
There are still lots of warnings to fix:
|
Now I give up :) |
You can run tests with tracemalloc to see where the object triggering ResourceWarnings was created: https://docs.python.org/dev/library/devmode.html#resourcewarning-example |
I would prefer to make it explicit that calling close() is recommended. That's why ResourceWarning is emitted if it's not called. |
We should indeed put more emphasis on that in the docs, but there is no reason to do it in every example. There's a lot of examples in the sqlite3 docs, and filling each and everyone of them with best practises is IMO not a good idea for well written docs :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But I don't get the two :skipif: True
. Does it mean that the cleanup is never executed? If yes, just remove it, no?
@erlend-aasland: Are you ok with this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm not sure what's going on with this PR. Once I saw "os.unlink()" calls, then they disappears. Does @sobolevn or @erlend-aasland plan to propose a following PR to call "os.unlink()"? I proposed using support.os_helper.unlink() which is more reliable when used in tests. |
They were fixed by Hugo in #117604, as I already said in #111730 (comment).
|
@vstinner: Sphinx recommends using its own machinery (
|
We cannot land this yet, there are still warnings to be fixed, as Nikita said in #111730 (comment). |
Great!
Oh, I'm lost in GitHub UI which hides comments when a comment is "solved".
Nah, it's not worth it, os.unlink() is fine. It was just a comment on a review.
I suggest to merge these fixes to make the situation clearer, since I'm lost in the lost history of this PR. You can, just remove "all" from the PR title :-) But it's up to you, if you want to first really fix all warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…stency with the doctest and testcleanup directives
@sobolevn, @vstinner: I fixed the remaining issues with f170f7c. It seems Sphinx has a problem with cc. @AA-Turner |
Sorry it took so long, Nikita! |
This comment was marked as outdated.
This comment was marked as outdated.
…tests (pythonGH-111730) (cherry picked from commit a770266) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
GH-117630 is a backport of this pull request to the 3.12 branch. |
@erlend-aasland thanks a lot for your help and for taking this over! 🤝 |
…ctests (GH-111730) (#117630) (cherry picked from commit a770266) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
…tests (python#111730) Co-authored-by: Erlend E. Aasland <[email protected]>
My logic behind this was:
.close()
to.. doctest::
, because it distracts people from the core example (except for cases, where it was already present).close()
to.. testcode::
, because one code part is better than twoDoc/library/sqlite3.rst
has multiple doctest warnings #111726📚 Documentation preview 📚: https://cpython-previews--111730.org.readthedocs.build/