Skip to content

Fix several ResourceWarnings: unclose file #46

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

Merged
merged 1 commit into from
Jan 2, 2019
Merged

Fix several ResourceWarnings: unclose file #46

merged 1 commit into from
Jan 2, 2019

Conversation

BoboTiG
Copy link
Contributor

@BoboTiG BoboTiG commented Jan 2, 2019

Hello,

This is a little patch for resource leaks such as:

$ python setup.py install
setup.py:14: ResourceWarning: unclosed file <_io.TextIOWrapper name='README.rst' mode='r' encoding='UTF-8'>
  long_description=open("README.rst").read(),
running install
...
$ bash examples/sample.sh
scatterplot.py:100: ResourceWarning: unclosed file <_io.TextIOWrapper name='examples/data/texas.txt' mode='r' encoding='UTF-8'>
  plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t)
with x and y coords
scatterplot.py:57: ResourceWarning: unclosed file <_io.TextIOWrapper name='examples/data/x_test.txt' mode='r' encoding='UTF-8'>
  xs = [float(str(row).strip()) for row in open(xs)]
scatterplot.py:58: ResourceWarning: unclosed file <_io.TextIOWrapper name='examples/data/y_test.txt' mode='r' encoding='UTF-8'>
  ys = [float(str(row).strip()) for row in open(ys)]

histogram.py:109: ResourceWarning: unclosed file <_io.TextIOWrapper name='examples/data/exp.txt' mode='r' encoding='UTF-8'>
  f = open(f).readlines()

I also fixed this error:

Traceback (most recent call last):
  File ".../bin/scatter", line 11, in <module>
    load_entry_point('bashplotlib==0.6.5', 'console_scripts', 'scatter')()
  File "scatterplot.py", line 100, in main
    plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t)
  File "scatterplot.py", line 74, in plot_scatter
    if cs:
UnboundLocalError: local variable 'cs' referenced before assignment

Signed-off-by: Mickaël Schoentgen contact@tiger-222.fr

Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
@glamp glamp merged commit 23319fe into glamp:master Jan 2, 2019
@BoboTiG BoboTiG deleted the fix-resource-leak branch January 2, 2019 18:19
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

Successfully merging this pull request may close these issues.

2 participants