<div dir="ltr"><div dir="ltr">Python GIL  doess't guarantee thread safety, and it only applies to python code. It only protects the internal state of the interpreter.</div><div dir="ltr">Moreover The C API offers the opportunity to release the GIL (see for example numpy [1]). </div><div dir="ltr"><br></div><div dir="ltr">Giovanni<br><div><br></div><div>[1] <a href="https://stackoverflow.com/a/36480941">https://stackoverflow.com/a/36480941</a></div></div></div><br><div class="gmail_quote"><div dir="ltr">Il giorno gio 25 ott 2018 alle ore 13:10 Alessandro Pasotti <<a href="mailto:apasotti@gmail.com">apasotti@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>I would go for multiprocess and stick to a single thread per-process.</div><div><br></div><div>But David may have a better advice.</div><div><br></div><div>Btw, it's nice to see a use case for Python Vector data providers :)<br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Oct 25, 2018 at 1:02 PM Radim Blazek <<a href="mailto:radim.blazek@gmail.com" target="_blank">radim.blazek@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If we narrow down the environment to uWSGI (with multiple threads<br>
enabled) running a Python application, which means that more instances<br>
of the same application may run in threads but never at the same time<br>
due to Python GIL (if I understand it well), is it still a problem? If<br>
we ensure that there are no static variables and singletons used by<br>
QGIS server? Is it then a problem to create/delete QObject on a non<br>
main thread?<br>
<br>
Radim<br>
On Sun, Nov 19, 2017 at 5:39 PM Martin Dobias <<a href="mailto:wonder.sk@gmail.com" target="_blank">wonder.sk@gmail.com</a>> wrote:<br>
><br>
> Hi Alessandro<br>
><br>
> On Sun, Nov 19, 2017 at 10:34 AM, Alessandro Pasotti <<a href="mailto:apasotti@gmail.com" target="_blank">apasotti@gmail.com</a>> wrote:<br>
> > Hi,<br>
> ><br>
> > mi recent experiments with multi-threaded python wrappers for QGIS server<br>
> > showed a critical flaw in my original implementation of the server plugins.<br>
> ><br>
> > First, I want to stress that this is not a problem in FCGI server<br>
> > implementation but only if the server is used directly from python in a<br>
> > multi threaded server implementation.<br>
> ><br>
> > The problem is that the server interface that exposes the request handler is<br>
> > a static property of the interface, that is changed on every request.<br>
> > This means that there is a race condition in setting/accessing the handler<br>
> > from a plugin filter, and that a plugin filter might access to the handler<br>
> > for a wrong request.<br>
><br>
> I think this is probably just the tip of the iceberg: most of the<br>
> classes in qgis_core are not thread-safe, and I believe the<br>
> implementation of server's services is not expected to be run in<br>
> multiple threads at once either. So even though things in theory could<br>
> work if requests are handled in multiple threads, most likely there<br>
> will be crashes. Even though map rendering was made to run safe in<br>
> multiple worker threads, there is still the assumption that the map<br>
> rendering is started from the main thread where all the objects live<br>
> (I'm talking about the QObject-based classes). Dealing with objects<br>
> like map layers or project in non-main thread is likely to end up<br>
> badly.<br>
><br>
> I would say for now we should simply stick with handling only one<br>
> request per server process at a time - just like how it is done with<br>
> the FastCGI implementation.<br>
><br>
> Cheers<br>
> Martin<br>
> _______________________________________________<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/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_2959880016667904230gmail_signature" data-smartmail="gmail_signature">Alessandro Pasotti<br>w3:   <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div>
_______________________________________________<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/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>