Skip to content

"ResourceWarning: unclosed file" warnings in the test suite #7167

Open

Description

@jrbourbeau

I noticed there are many warnings that look like:

dask/bytes/tests/test_http.py::test_simple
  /usr/share/miniconda3/envs/test-environment/lib/python3.8/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]>
  
  Traceback (most recent call last):
    File "/home/runner/work/dask/dask/dask/bytes/tests/test_http.py", line 50, in test_simple
      assert data == open(os.path.join(dir_server, fn), "rb").read()
  ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/tmp2zbuwztd/a'>
  
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

in the test suite (see this build for an example). It would be good at some point to go through and resolve these warnings.

Activity

  1. jsignell commented on Mar 2, 2021

    @jsignell
    Member

    A lot of these are also coming from parquet. It doesn't seem like there is any attempt at closing files in pyarrow. I am not sure how best to workaround this or if I am missing something. In particular, these parts seem to cause issues:

      Traceback (most recent call last):
        File "/home/julia/dask/dask/dataframe/io/parquet/arrow.py", line 1586, in _parquet_piece_as_arrow
          arrow_table = piece.read(
      ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pytest-of-julia/pytest-39/popen-gw7/test_select_partitioned_column1/fake_categorical1=C/fake_categorical2=E/part.1.parquet'>
    
      Traceback (most recent call last):
        File "/home/julia/dask/dask/dataframe/io/parquet/arrow.py", line 1786, in _gather_metadata
          md = piece.get_metadata()
      ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pytest-of-julia/pytest-39/popen-gw7/test_categories_large_pyarrow_0/parquet_int16.parq'>
    

    I am wondering if we need to write our own versions of get_metadata and piece.read @rjzamora

  2. jsignell commented on Mar 2, 2021

    @jsignell
    Member

    I will open a PR to try to make this discussion clearer.

  3. jrbourbeau commented on Mar 2, 2021

    @jrbourbeau
    MemberAuthor

    Awesome, thanks @jsignell

  4. GenevieveBuckley commented on Sep 2, 2021

    @GenevieveBuckley
    Contributor

    7303 was a partial fix - should this issue be kept open to track the remaining arrow stuff?

  5. jrbourbeau commented on Sep 2, 2021

    @jrbourbeau
    MemberAuthor

    Whoops, good catch @GenevieveBuckley -- reopening

  6. added
    tests
    needs info
    on Oct 14, 2021
  7. GenevieveBuckley commented on Oct 14, 2021

    @GenevieveBuckley
    Contributor

    @jrbourbeau I've recently been doing a lot of running the test suite locally, and I'm not seeing the kinds of warnings you described.
    Is this still happening for you? If not, perhaps we can close the issue.

  8. jrbourbeau commented on Oct 14, 2021

    @jrbourbeau
    MemberAuthor

    Just checked the latest CI build on main and, indeed, these unclosed file ResourceWarning are gone 🎉

    Thanks for following-up here @GenevieveBuckley

  9. j-bennet commented on Mar 15, 2023

    @j-bennet
    Contributor

    This came up again, CI job:

    https://github.com/dask/dask/actions/runs/4421267540/jobs/7751871262

    dask/dataframe/io/tests/test_parquet.py::test_retries_on_remote_filesystem
      /usr/share/miniconda3/envs/test-environment/lib/python3.10/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]>
      
      Traceback (most recent call last):
        File "/home/runner/work/dask/dask/dask/dataframe/io/parquet/arrow.py", line 1005, in _collect_dataset_info
          physical_schema = file_frag.physical_schema
      ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/tmp57eq_7ze/d549ad8b59c1797315fcb393c08f3fb30bf1195da24aabd1b0dca178e4f34afd'>
      
        warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
    

    Reopening to fix again.

  10. added
    needs attention
    on Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs attentionneeds infotests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions