<div dir="ltr">Hi Matthias,<div><br></div><div>thanks for the heads up on subprocess.Popen.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Best,</div><div>-Andreas</div><div><br><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Date: Mon, 22 May 2017 08:22:44 +0200<br>
From: Matthias Kuhn <<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a>><br>
To: <a href="mailto:qgis-developer@lists.osgeo.org">qgis-developer@lists.osgeo.org</a><br>
Subject: Re: [QGIS-Developer] [processing] launching separate<br>
        process/thread<br><br>
Hi Andreas,<br>
<br>
I recently had troubles with getting stdout / stderr from<br>
subprocess.Popen on some Windows systems. Not sure about the reasons but<br>
switching over to QProcess solved it.<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 5/21/17 11:55 PM, Andreas Plesch wrote:<br>
> Looking around some more, there is also os.spawn and its recommended<br>
> update subprocess.Popen.<br>
><br>
> So<br>
><br>
> os.chdir(root_folder)<br>
> pid = subprocess.Popen(['python', '-m', 'SimpleHTTPServer',<br>
> str(port)]).pid<br>
><br>
> and later<br>
> os.kill(pid, 7)<br>
><br>
> works robustly in my tests. This seems similar to<br>
> QProcess.startDetached which may provide better platform coverage (?).<br>
><br>
> -Andreas<br>
><br>
><br>
><br>
><br>
> On Sun, May 21, 2017 at 9:30 AM, Andreas Plesch<br>
> <<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.com</a> <mailto:<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.<wbr>com</a>>> wrote:<br>
><br>
>     Hi Giovanni,<br>
><br>
>     thanks for the pointer. When I use multiprocessing.Process instead<br>
>     of threading.Thread I get:<br>
><br>
>     PicklingError: Can't pickle <function webserver at 0x1622F330>:<br>
>     it's not found as __main__.webserver<br>
><br>
>     This is probably related to:<br>
><br>
>     <a href="https://docs.python.org/2/library/multiprocessing.html#windows" rel="noreferrer" target="_blank">https://docs.python.org/2/<wbr>library/multiprocessing.html#<wbr>windows</a><br>
>     <<a href="https://docs.python.org/2/library/multiprocessing.html#windows" rel="noreferrer" target="_blank">https://docs.python.org/2/<wbr>library/multiprocessing.html#<wbr>windows</a>><br>
><br>
>     So I am not sure how one would use multiprocessing from a<br>
>     processing script rather than from the __main__ python program.<br>
><br>
>     -Andreas<br>
><br>
><br>
>     On Sun, May 21, 2017 at 8:45 AM, G. Allegri <<a href="mailto:giohappy@gmail.com">giohappy@gmail.com</a><br>
>     <mailto:<a href="mailto:giohappy@gmail.com">giohappy@gmail.com</a>>> wrote:<br>
><br>
>         Side note: multiprocessing is part of the Python standard<br>
>         library.<br>
>         <a href="https://docs.python.org/2.7/library/multiprocessing.html" rel="noreferrer" target="_blank">https://docs.python.org/2.7/<wbr>library/multiprocessing.html</a><br>
>         <<a href="https://docs.python.org/2.7/library/multiprocessing.html" rel="noreferrer" target="_blank">https://docs.python.org/2.7/<wbr>library/multiprocessing.html</a>><br>
><br>
>         Giovanni<br>
><br>
>         Il 21 mag 2017 14:18, "Andreas Plesch"<br>
>         <<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.com</a> <mailto:<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.<wbr>com</a>>> ha<br>
>         scritto:<br>
><br>
>             As a followup, here is the simple processing script which<br>
>             is my attempt at launching a separate task:<br>
><br>
>             <a href="https://github.com/andreasplesch/QGIS-X3D-Processing/blob/master/scripts/launch_webserver.py" rel="noreferrer" target="_blank">https://github.com/<wbr>andreasplesch/QGIS-X3D-<wbr>Processing/blob/master/<wbr>scripts/launch_webserver.py</a><br>
>             <<a href="https://github.com/andreasplesch/QGIS-X3D-Processing/blob/master/scripts/launch_webserver.py" rel="noreferrer" target="_blank">https://github.com/<wbr>andreasplesch/QGIS-X3D-<wbr>Processing/blob/master/<wbr>scripts/launch_webserver.py</a>><br>
><br>
>             qgis2web does not seem to need a real http server for the<br>
>             preview as openlayers apparently can use the file protocol.<br>
><br>
>             -Andreas<br>
><br>
>             On Sat, May 20, 2017 at 5:29 PM, Andreas Plesch<br>
>             <<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.com</a> <mailto:<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.<wbr>com</a>>><br>
>             wrote:<br>
><br>
>                 I would like to launch a minimal web server from a<br>
>                 processing script to serve html properly (rather than<br>
>                 using the file protocol).<br>
><br>
>                 Since the web server needs to run and keep running<br>
>                 separately from qgis or the qgis python interpreter, I<br>
>                 investigated various ways to accomplish this using<br>
>                 SimpleHTTPServer. On windows 2.18.7 as linux should be<br>
>                 more robust.<br>
><br>
>                 - threading.Threat : start() works until the server<br>
>                 actually serves a file. Then qgis crashes with a<br>
>                 minidump . For some reason, the crashing happens not<br>
>                 always but more often than not.<br>
>                 - multiprocessing : seems to be the recommended<br>
>                 solution but I do not seem to have it with Qgis python (?)<br>
>                 - QProcess.start() : works from the python terminal,<br>
>                 seems robust but does not seem to work from a<br>
>                 processing script (?). Would be the preferred solution.<br>
>                 - QProcess.startDetached('<wbr>python',(args),dir) : works<br>
>                 reliably but requires killing and restarting the<br>
>                 process to change the root directory served<br>
><br>
>                 This may all change with Qgis 3 but I suspect 2.18<br>
>                 will be around for a while, too.<br>
><br>
>                 Any recommendations or ideas would be welcome.<br>
><br>
>                 I will look into qgis2web to see what it does.<br>
><br>
>                 --<br>
>                 Andreas Plesch<br>
>                 39 Barbara Rd.<br>
>                 Waltham, MA 02453<br>
><br>
><br>
><br>
><br>
>             --<br>
>             Andreas Plesch<br>
>             39 Barbara Rd.<br>
>             Waltham, MA 02453<br>
><br>
>             ______________________________<wbr>_________________<br>
>             QGIS-Developer mailing list<br>
>             <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
>             <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>><br>
>             List info:<br>
>             <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>             <<a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a>><br>
>             Unsubscribe:<br>
>             <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>             <<a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a>><br>
><br>
><br>
><br>
><br>
>     --<br>
>     Andreas Plesch<br>
>     39 Barbara Rd.<br>
>     Waltham, MA 02453<br>
><br>
><br>
><br>
><br>
> --<br>
> Andreas Plesch<br>
> 39 Barbara Rd.<br>
> Waltham, MA 02453<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170522/63250ee4/attachment.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>pipermail/qgis-developer/<wbr>attachments/20170522/63250ee4/<wbr>attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
<br>
------------------------------<br>
<br>
End of QGIS-Developer Digest, Vol 139, Issue 59<br>
******************************<wbr>*****************<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</div></div></div></div>