#28833 closed defect (fixed)

ResourceWarning: unclosed file with SAGE_DEBUG=yes

Reported by: vbraun Owned by:
Priority: major Milestone: sage-9.0
Component: graphics Keywords:
Cc: Merged in:
Authors: Frédéric Chapoton Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: 1db03d6 (Commits, GitHub, GitLab) Commit: 1db03d67c2e30b9b9ae507d7e4a6d4d15b951352
Dependencies: Stopgaps:

Status badges

Description (last modified by vbraun)

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

Change History (8)

comment:1 Changed 23 months ago by vbraun

  • Component changed from PLEASE CHANGE to graphics
  • Description modified (diff)
  • Type changed from PLEASE CHANGE to defect

comment:2 Changed 23 months ago by chapoton

  • Authors set to Frédéric Chapoton
  • Branch set to u/chapoton/28833
  • Commit set to 9c00054687567f83a6134a4503f9d82732f48649

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


New commits:

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

comment:3 Changed 23 months ago by git

  • Commit changed from 9c00054687567f83a6134a4503f9d82732f48649 to 1db03d67c2e30b9b9ae507d7e4a6d4d15b951352

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

1db03d6trac 28833 fix doctests

comment:4 Changed 23 months ago by chapoton

green bot

comment:5 Changed 23 months ago by vbraun

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)

comment:6 Changed 23 months ago by chapoton

  • Reviewers set to Volker Braun
  • Status changed from new to needs_review

Let us first merge this.

comment:7 Changed 23 months ago by chapoton

  • Status changed from needs_review to positive_review

comment:8 Changed 23 months ago by vbraun

  • Branch changed from u/chapoton/28833 to 1db03d67c2e30b9b9ae507d7e4a6d4d15b951352
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.