Skip to content

ResouceWarning on Python 3.14 from unclosed tempfile.NamedTemporaryFile #1134

Description

@mroeschke
import warnings
 
import numpy as np
import stumpy

with warnings.catch_warnings():
    warnings.filterwarnings("error", category=ResourceWarning)

    rng = np.random.default_rng(42)
    your_time_series = rng.random(10000)
    window_size = (
        50  # Approximately, how many data points might be found in a pattern
    )
    stumpy.gpu_stump(your_time_series, m=window_size, device_id=0)

Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp1ardm6k6'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpwze200r5'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmphuv6pm3j'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp4_v59e8o'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpuom17x__'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp2r10jnt6'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmphejxa2ki'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpv50nsq6c'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp88ucwns2'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpgw8vwrs6'>>
/miniforge3/envs/test-stumpy/lib/python3.14/site-packages/numba/cuda/dispatcher.py:536: NumbaPerformanceWarning: Grid size 20 will likely result in GPU under-utilization due to low occupancy.
  warn(NumbaPerformanceWarning(msg))
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp_ev3_olu'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpbr37tx23'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp4jdjzhyl'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp2x6jukyf'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmp2_79_g0d'>>
Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0x7932ed931590>:
Traceback (most recent call last):
  File "/miniforge3/envs/test-stumpy/lib/python3.14/tempfile.py", line 484, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <_TemporaryFileWrapper file=<_io.BufferedRandom name='/tmp/tmpgrv1ipxp'>>
mparray([[6.863254359622374, 3181, -1, 3181],
         [6.64154485072902, 3182, -1, 3182],
         [6.830177331061536, 3183, -1, 3183],
         ...,
         [6.960611650535677, 970, 970, -1],
         [6.97346754087878, 971, 971, -1],
         [6.800287895530834, 972, 972, -1]], shape=(9951, 4), dtype=object)

I believe this call is creating a temporary file that is never closed

fname = tempfile.NamedTemporaryFile(delete=False)

Activity

  1. seanlaw commented on Apr 23, 2026

    @seanlaw
    Contributor

    @mroeschke Thank you for brining this to our attention! In the stumpy/gpu_stump.py file, the temp files are deleted via calls to os.remove. I wonder if it is enough to close the temp file prior to deleting the file?

  2. mroeschke commented on Apr 23, 2026

    @mroeschke
    Author

    I wonder if it is enough to close the temp file prior to deleting the file?

    Yup, that should be sufficient, or use the context manager to ensure the file is closed even if there are errors before the os.remove e.g.

    with core.array_to_temp_file(T_A) as T_A_fname:
        ...

    And the default delete_on_close=True argument in NamedTemporaryFile with the context manager should make the os.remove unnecessary

  3. self-assigned this
    on Apr 24, 2026
  4. seanlaw commented on Apr 24, 2026

    @seanlaw
    Contributor

    @mroeschke I don't have access to a GPU at the moment. Are you able to test if this PR fixes the issue for you?

  5. added a commit that references this issue on Apr 30, 2026
    8b3daf9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions