Skip to content
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

ResourceWarning: unclosed file with SAGE_DEBUG=yes #28833

Closed
vbraun opened this issue Dec 2, 2019 · 12 comments
Closed

ResourceWarning: unclosed file with SAGE_DEBUG=yes #28833

vbraun opened this issue Dec 2, 2019 · 12 comments

Comments

@vbraun
Copy link
Member

vbraun commented Dec 2, 2019

Python 3 now emits a ResourceWarning if you use the quick'n dirty open(...).read() to read (or write) a file instead of a with context. This leads to lots and lots of test failures of the form:

File "src/doc/en/prep/Symbolics-and-Basic-Plotting.rst", line 487, in doc.en.prep.Symbolics-and-Basic-Plotting
Failed example:
    implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=50, color='yellow')
Expected:
    Graphics3d Object
Got:
    doctest:warning
      File "/home/buildbot-sage/slave/sage_git/build/src/bin/sage-runtests", line 179, in <module>
        err = DC.run()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/control.py", line 1238, in run
        self.run_doctests()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/control.py", line 939, in run_do
ctests
        self.dispatcher.dispatch()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 2033, in dispat
ch
        self.parallel_dispatch()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1925, in parall
el_dispatch
        w.start()  # This might take some time
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 2200, in start
        super(DocTestWorker, self).start()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/process.py", line 112, in start
        self._popen = self._Popen(self)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/context.py", line 223, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/context.py", line 277, in _Popen
        return Popen(process_obj)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
        self._launch(process_obj)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/popen_fork.py", line 74, in _launch
        code = process_obj._bootstrap()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
        self.run()
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 2172, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 2504, in __call
__
        doctests, extras = self._run(runner, options, results)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 2553, in _run
        result = runner.run(test)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 897, in run
        return self._run(test, compileflags, out)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1123, in compil
e_and_execute
        exec(compiled, globs)
      File "<doctest doc.en.prep.Symbolics-and-Basic-Plotting[45]>", line 1, in <module>
        implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=Integer(50), color='yellow')
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/repl/rich_output/display_manager.py", line 811, in displayhook
        plain_text, rich_output = self._rich_output_formatter(obj, dict())
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/repl/rich_output/display_manager.py", line 625, in _rich_output_formatter
        rich_output = self._call_rich_repr(obj, rich_repr_kwds)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/repl/rich_output/display_manager.py", line 585, in _call_rich_repr
        return obj._rich_repr_(self)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/site-packages/sage/interfaces/tachyon.py", line 138, in __call__
        open(modelfile,'w').write(model)
      File "/home/buildbot-sage/slave/sage_git/build/local/lib/python3.7/warnings.py", line 110, in _showwarnmsg
        msg.file, msg.line)
    :
    ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/buildbot-sage/slave/sage_git/dot_sage/temp/zen/3222347/tmp_j8lfc7ax.dat' mode='w' encoding='UTF-8'>
    Graphics3d Object

Component: graphics

Author: Frédéric Chapoton

Branch/Commit: 1db03d6

Reviewer: Volker Braun

Issue created by migration from https://trac.sagemath.org/ticket/28833

@vbraun vbraun added this to the sage-9.0 milestone Dec 2, 2019
@vbraun

This comment has been minimized.

@fchapoton
Copy link
Contributor

Branch: u/chapoton/28833

@fchapoton
Copy link
Contributor

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor

Commit: 9c00054

@fchapoton
Copy link
Contributor

comment:2

Here is a first tentative. I may have missed some.


New commits:

9c00054trac 28833 adding a bunch of with open ... context managers

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 3, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

1db03d6trac 28833 fix doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 3, 2019

Changed commit from 9c00054 to 1db03d6

@fchapoton
Copy link
Contributor

comment:4

green bot

@vbraun
Copy link
Member Author

vbraun commented Dec 3, 2019

comment:5

There are a couple of others, e.g. use

egrep -r 'open\([^)]*\)\.read' src/sage

but we can also postpone these for later if you rather want to merge the current state (please set to positive review in that case)

@fchapoton
Copy link
Contributor

comment:6

Let us first merge this.

@fchapoton
Copy link
Contributor

Reviewer: Volker Braun

@vbraun
Copy link
Member Author

vbraun commented Dec 8, 2019

Changed branch from u/chapoton/28833 to 1db03d6

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

No branches or pull requests

2 participants