On Thursday, June 2, 2016 at 11:55:41 PM UTC+2, Cristiano Coelho wrote:
>
> Not always, for example, on amazon elastic beasntalk when you either 
> restart the app server or upload a new version, it basically kills apache 
> and all WSGI processes through a sigterm
>

A SIGTERM is a normal signal an should cause a proper shutdown.
 

> so those thread pools are probably killed in a bad way and you don't 
> really have control over that.
>

Absolutely not, you are mixing up SIGTERM and SIGKILL.
 

> Also you don't really have control on the life of a thread pool thread, so 
> a given thread could be gracefully stopped by the pool implementation
>

Once again: there is no pool. 

As ayneric pointed out, it seems like those connections are correctly 
> closed most of the time when a thread dies, but for some reason, postgres 
> would keep some connections opened.
>

If a connection is closed properly, postgres will close it accordingly. The 
only way possible for a connection to stay open while the app is gone is 
that you are running into tcp timeouts while getting killed with SIGTERM 
(dunno if the postgres protocol has keep alive support on the protocol 
level, most likely not). As long as you are not sending a SIGTERM, python 
should clean up properly which should call garbage collection, which then 
again should delete all connections and therefore close the connection. Any 
other behavior seems like a bug in Python (or maybe Django, but as long as 
Python shuts down properly I think we are fine).

Are there any rare cases where even if the thread is stopped the connection 
> won't be closed? The only thing I can think of are that those threads are 
> never garbage collected or something.
>

Depends on the python version you are using, especially thread local 
behavior changed a lot…

Cheers,
Florian 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0387d845-c490-4527-b33f-e0caf99696a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to