<div dir="ltr"><div><div><div>Looking around some more, there is also os.spawn and its recommended update subprocess.Popen.<br><br></div><div>So<br><br>os.chdir(root_folder)<br>pid = subprocess.Popen(['python', '-m', 'SimpleHTTPServer', str(port)]).pid<br></div><br></div>and later <br></div>os.kill(pid, 7)<br><div><div><br></div><div>works robustly in my tests. This seems similar to QProcess.startDetached which may provide better platform coverage (?).<br></div><div><br></div><div>-Andreas<br></div><div><br> <br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 21, 2017 at 9:30 AM, Andreas Plesch <span dir="ltr"><<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Giovanni,<div><br></div><div>thanks for the pointer. When I use multiprocessing.Process instead of threading.Thread I get:</div><div><br></div><div>PicklingError: Can't pickle <function webserver at 0x1622F330>: it's not found as __main__.webserver<br></div><div><br></div><div>This is probably related to:</div><div><br></div><div><a href="https://docs.python.org/2/library/multiprocessing.html#windows" target="_blank">https://docs.python.org/2/<wbr>library/multiprocessing.html#<wbr>windows</a><br></div><div><br></div><div>So I am not sure how one would use multiprocessing from a processing script rather than from the __main__ python program. </div><div><br></div><div>-Andreas</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 21, 2017 at 8:45 AM, G. Allegri <span dir="ltr"><<a href="mailto:giohappy@gmail.com" target="_blank">giohappy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Side note: multiprocessing is part of the Python standard library.<div dir="auto"><a href="https://docs.python.org/2.7/library/multiprocessing.html" target="_blank">https://docs.python.org/2.7/li<wbr>brary/multiprocessing.html</a><br></div><div dir="auto"><br></div><div dir="auto">Giovanni</div></div><div class="gmail_extra"><br><div class="gmail_quote">Il 21 mag 2017 14:18, "Andreas Plesch" <<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>> ha scritto:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As a followup, here is the simple processing script which is my attempt at launching a separate task:<div><br></div><div><a href="https://github.com/andreasplesch/QGIS-X3D-Processing/blob/master/scripts/launch_webserver.py" target="_blank">https://github.com/andreasples<wbr>ch/QGIS-X3D-Processing/blob/ma<wbr>ster/scripts/launch_webserver.<wbr>py</a><br></div><div><br></div><div>qgis2web does not seem to need a real http server for the preview as openlayers apparently can use the file protocol.</div><div><br></div><div>-Andreas<br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 20, 2017 at 5:29 PM, Andreas Plesch <span dir="ltr"><<a href="mailto:andreasplesch@gmail.com" target="_blank">andreasplesch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I would like to launch a minimal web server from a processing script to serve html properly (rather than using the file protocol).<div><br></div><div>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.</div><div><br></div><div>- 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.</div><div>- multiprocessing : seems to be the recommended solution but I do not seem to have it with Qgis python (?)</div><div>- QProcess.start() : works from the python terminal, seems robust but does not seem to work from a processing script (?). Would be the preferred solution.</div><div>- QProcess.startDetached('python<wbr>',(args),dir) : works reliably but requires killing and restarting the process to change the root directory served</div><div><br></div><div><div>This may all change with Qgis 3 but I suspect 2.18 will be around for a while, too.</div><div><br></div><div>Any recommendations or ideas would be welcome.</div><div><br></div><div>I will look into qgis2web to see what it does.</div><span class="m_5715314223691126606HOEnZb"><font color="#888888"><span class="m_5715314223691126606m_-8717717480193625739m_7754341851245049440gmail-HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_5715314223691126606m_-8717717480193625739m_7754341851245049440gmail-m_1640074130608958439gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></font></span></div></div><span class="m_5715314223691126606HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="m_5715314223691126606HOEnZb"><font color="#888888"><br><br clear="all"><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_5715314223691126606m_-8717717480193625739m_7754341851245049440gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></font></span></div></div></div><span class="HOEnZb"><font color="#888888"><span class="m_5715314223691126606HOEnZb"><font color="#888888">
<br>______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">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/mailma<wbr>n/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/qgis-developer</a><br></font></span></font></span></blockquote></div></div><span class="HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_5715314223691126606gmail_signature" data-smartmail="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Andreas Plesch<br>39 Barbara Rd.<br>Waltham, MA 02453</div>
</div>