[QGIS-Developer] Python ResourceWarning: unclosed file in Processing Plugin

Martin Isenburg martin.isenburg at gmail.com
Tue Sep 4 04:10:56 PDT 2018


Hello.

thanks for the suggestion. I tried this instead:

        output = subprocess.Popen(commandline, shell=True,
stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT,
universal_newlines=False)
        output.wait()
        feedback.pushConsoleInfo(output.communicate()[0].decode("utf-8"))

but as soon as the subprocess is started (long before it completes) this
WARNING is output to the console.

2018-09-04T13:05:31     WARNING
warning:C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStoolsUtils.py:60:
ResourceWarning:

             unclosed file

             traceback: File
"C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStools\lasview.py",
line 67, in processAlgorithm
              LAStoolsUtils.runLAStools(commands, feedback)
              File
"C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStoolsUtils.py",
line 60, in runLAStools
              output = subprocess.Popen(commandline, shell=True,
stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT,
universal_newlines=False)


how do others grab the stderr output off their subprocesses for display in
the console?


Martin

On Tue, Sep 4, 2018 at 1:03 AM Nyall Dawson <nyall.dawson at gmail.com> wrote:

> On Tue, 4 Sep 2018 at 02:56, Martin Isenburg <martin.isenburg at gmail.com>
> wrote:
> >
> > Hello,
> >
> > as soon as I run any of my LAStools plugin scripts I get the WARNING
> "ResourceWarning" about an "unclosed file" shown below in the Python
> warning window. I use the call "output = subprocess.Popen(....)" to get the
> stderr output from the process so I can push it to the console once the
> subprocess is complete with the
> feedback.pushConsoleInfo(output.decode("utf-8")). Is it bad? Can I fix it?
> Should I ignore it?
> >
> > Complete code:
> >
> >
> https://github.com/rapidlasso/LAStoolsPluginQGIS3/blob/master/LAStools/LAStoolsUtils.py
> >
> > Regards.
> >
> > Martin
> >
> > 2018-09-03T18:34:08     WARNING
> warning:C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStoolsUtils.py:60:
> ResourceWarning:
> >
> >              unclosed file
> >
> >              traceback: File
> "C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStoolsPipelines\flightlinesToDTMandSpikeFreeDSM.py",
> line 82, in processAlgorithm
> >               LAStoolsUtils.runLAStools(commands, feedback)
> >               File
> "C:/Users/isenburg/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LAStools\LAStoolsUtils.py",
> line 60, in runLAStools
> >               output = subprocess.Popen(commandline, shell=True,
> stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT,
> universal_newlines=False).communicate()[0]
>
> I think you need a:
>
> output.wait()
>
> after this line. See
>
> https://stackoverflow.com/questions/23279941/closing-stdin-in-subprocess-popen
>
> Nyall
>
>
> >
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180904/b166d263/attachment.html>


More information about the QGIS-Developer mailing list