8000 ResourceWarning: unclosed file · Issue #534 · simonw/sqlite-utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ResourceWarning: unclosed file #534

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

Closed
djhenderson opened this issue Mar 14, 2023 · 1 comment
Closed

ResourceWarning: unclosed file #534

djhenderson opened this issue Mar 14, 2023 · 1 comment

Comments

@djhenderson
Copy link

Issuing either

py -Wdefault -m sqlite_utils insert dogs.db dogs dogs0.csv --csv
  [#############-----------------------]   36%
  [####################################]  100%C:\Users\Doug\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlite_utils\cli.py:1187: ResourceWarning: unclosed file <_io.TextIOWrapper name='dogs0.csv' encoding='utf-8-sig'>
  insert_upsert_implementation(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

or

set pythonwarnings=default
sqlite-utils insert dogs.db dogs dogs0.csv --csv
  [#############-----------------------]   36%
  [####################################]  100%C:\Users\Doug\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlite_utils\cli.py:1187: ResourceWarning: unclosed file <_io.TextIOWrapper name='dogs0.csv' encoding='utf-8-sig'>
  insert_upsert_implementation(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

exhibits a ResourceWarning indicating that the CSV file being loaded is not closed.

sqlite-utils --version
sqlite-utils, version 3.30
py --version
Python 3.11.2
Windows Version 10.0.19045 Build 19045
SQLite version 3.41.0 2023-02-21 18:09:37

@simonw
Copy link
Owner
simonw commented May 8, 2023

On macOS this shows the same warning:

% python -Wdefault $(which sqlite-utils) insert dogs.db dogs dogs.csv --csv
  [############------------------------]   35%
  [####################################]  100%/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/cli.py:1187: ResourceWarning: unclosed file <_io.TextIOWrapper name='dogs.csv' encoding='utf-8-sig'>
  insert_upsert_implementation(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

The file itself is a click.File which is automatically closed - https://click.palletsprojects.com/en/8.1.x/api/#click.File - but it looks like it's the _io.TextIOWrapper which is not being closed:

# The --sniff option needs us to buffer the file to peek ahead
sniff_buffer = None
if sniff:
sniff_buffer = io.BufferedReader(file, buffer_size=4096)
decoded = io.TextIOWrapper(sniff_buffer, encoding=encoding)
else:
decoded = io.TextIOWrapper(file, encoding=encoding)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0