[QGIS-Developer] [processing] launching separate process/thread

Andreas Plesch andreasplesch at gmail.com
Mon May 22 13:12:06 PDT 2017


Hi Matthias,

thanks for the heads up on subprocess.Popen.

While for spawning a simple webserver, no communication is needed at this
point, QProcess may then also work better if I can find out how to change
the root folder of a running instance of SimpleHTTPServer.

Could you use QProcess.start() rather than QProcess.startDetached() from a
plugin or processing script ? I am looking for a way to avoid having the
console window open up.

Best,
-Andreas


> Date: Mon, 22 May 2017 08:22:44 +0200
> From: Matthias Kuhn <matthias at opengis.ch>
> To: qgis-developer at lists.osgeo.org
> Subject: Re: [QGIS-Developer] [processing] launching separate
>         process/thread
>
> Hi Andreas,
>
> I recently had troubles with getting stdout / stderr from
> subprocess.Popen on some Windows systems. Not sure about the reasons but
> switching over to QProcess solved it.
>

> On 5/21/17 11:55 PM, Andreas Plesch wrote:
> > Looking around some more, there is also os.spawn and its recommended
> > update subprocess.Popen.
> >
> > So
> >
> > os.chdir(root_folder)
> > pid = subprocess.Popen(['python', '-m', 'SimpleHTTPServer',
> > str(port)]).pid
> >
> > and later
> > os.kill(pid, 7)
> >
> > works robustly in my tests. This seems similar to
> > QProcess.startDetached which may provide better platform coverage (?).
> >
> > -Andreas
> >
> >
> >
> >
> > On Sun, May 21, 2017 at 9:30 AM, Andreas Plesch
> > <andreasplesch at gmail.com <mailto:andreasplesch at gmail.com>> wrote:
> >
> >     Hi Giovanni,
> >
> >     thanks for the pointer. When I use multiprocessing.Process instead
> >     of threading.Thread I get:
> >
> >     PicklingError: Can't pickle <function webserver at 0x1622F330>:
> >     it's not found as __main__.webserver
> >
> >     This is probably related to:
> >
> >     https://docs.python.org/2/library/multiprocessing.html#windows
> >     <https://docs.python.org/2/library/multiprocessing.html#windows>
> >
> >     So I am not sure how one would use multiprocessing from a
> >     processing script rather than from the __main__ python program.
> >
> >     -Andreas
> >
> >
> >     On Sun, May 21, 2017 at 8:45 AM, G. Allegri <giohappy at gmail.com
> >     <mailto:giohappy at gmail.com>> wrote:
> >
> >         Side note: multiprocessing is part of the Python standard
> >         library.
> >         https://docs.python.org/2.7/library/multiprocessing.html
> >         <https://docs.python.org/2.7/library/multiprocessing.html>
> >
> >         Giovanni
> >
> >         Il 21 mag 2017 14:18, "Andreas Plesch"
> >         <andreasplesch at gmail.com <mailto:andreasplesch at gmail.com>> ha
> >         scritto:
> >
> >             As a followup, here is the simple processing script which
> >             is my attempt at launching a separate task:
> >
> >             https://github.com/andreasplesch/QGIS-X3D-
> Processing/blob/master/scripts/launch_webserver.py
> >             <https://github.com/andreasplesch/QGIS-X3D-
> Processing/blob/master/scripts/launch_webserver.py>
> >
> >             qgis2web does not seem to need a real http server for the
> >             preview as openlayers apparently can use the file protocol.
> >
> >             -Andreas
> >
> >             On Sat, May 20, 2017 at 5:29 PM, Andreas Plesch
> >             <andreasplesch at gmail.com <mailto:andreasplesch at gmail.com>>
> >             wrote:
> >
> >                 I would like to launch a minimal web server from a
> >                 processing script to serve html properly (rather than
> >                 using the file protocol).
> >
> >                 Since the web server needs to run and keep running
> >                 separately from qgis or the qgis python interpreter, I
> >                 investigated various ways to accomplish this using
> >                 SimpleHTTPServer. On windows 2.18.7 as linux should be
> >                 more robust.
> >
> >                 - threading.Threat : start() works until the server
> >                 actually serves a file. Then qgis crashes with a
> >                 minidump . For some reason, the crashing happens not
> >                 always but more often than not.
> >                 - multiprocessing : seems to be the recommended
> >                 solution but I do not seem to have it with Qgis python
> (?)
> >                 - QProcess.start() : works from the python terminal,
> >                 seems robust but does not seem to work from a
> >                 processing script (?). Would be the preferred solution.
> >                 - QProcess.startDetached('python',(args),dir) : works
> >                 reliably but requires killing and restarting the
> >                 process to change the root directory served
> >
> >                 This may all change with Qgis 3 but I suspect 2.18
> >                 will be around for a while, too.
> >
> >                 Any recommendations or ideas would be welcome.
> >
> >                 I will look into qgis2web to see what it does.
> >
> >                 --
> >                 Andreas Plesch
> >                 39 Barbara Rd.
> >                 Waltham, MA 02453
> >
> >
> >
> >
> >             --
> >             Andreas Plesch
> >             39 Barbara Rd.
> >             Waltham, MA 02453
> >
> >             _______________________________________________
> >             QGIS-Developer mailing list
> >             QGIS-Developer at lists.osgeo.org
> >             <mailto:QGIS-Developer at lists.osgeo.org>
> >             List info:
> >             https://lists.osgeo.org/mailman/listinfo/qgis-developer
> >             <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> >             Unsubscribe:
> >             https://lists.osgeo.org/mailman/listinfo/qgis-developer
> >             <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> >
> >
> >
> >
> >     --
> >     Andreas Plesch
> >     39 Barbara Rd.
> >     Waltham, MA 02453
> >
> >
> >
> >
> > --
> > Andreas Plesch
> > 39 Barbara Rd.
> > Waltham, MA 02453
> >
> >
> > _______________________________________________
> > 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/20170522/63250ee4/attachment.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> 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
>
> ------------------------------
>
> End of QGIS-Developer Digest, Vol 139, Issue 59
> ***********************************************
>



-- 
Andreas Plesch
39 Barbara Rd.
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170522/a1e3a72f/attachment.html>


More information about the QGIS-Developer mailing list