Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Graham Dumpleton
If you want to be able to control a thread like that from an atexit callback, you need to create the thread as daemonised. Ie. setDaemon(True) call on thread. By default a thread will actually inherit the daemon flag from the parent. For a command line Python where thread created from main thread

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Simon Sapin
Simon Sapin a écrit : >Both of these callbacks could be called once per process (aka. space >where requests share memory.) Sorry, that should be once per interpreter. -- Simon Sapin ___ Web-SIG mailing list Web-SIG@python.org Web SIG: http://www.p

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
for the record: http://bugs.python.org/issue14073 On Tue, Feb 21, 2012 at 3:06 PM, Tarek Ziadé wrote: > On Tue, Feb 21, 2012 at 3:02 PM, Antoine Pitrou wrote: > >> ... >> I find your example convincing. I think that's worth fixing in Python >> (e.g. by >> offering an atexit() method on Thread ob

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 3:02 PM, Antoine Pitrou wrote: > ... > I find your example convincing. I think that's worth fixing in Python > (e.g. by > offering an atexit() method on Thread objects). Perhaps you can open a bug? > Sure yeah -- Notice that I think it's still a good idea to provide the

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Antoine Pitrou
Tarek Ziadé writes: > > here's a very simple demo: http://tarek.pastebin.mozilla.org/1489505 > > There are two typos but the effect remains the same since you are locked > before you reach those lines: > - atexit call worker.stop() instead  > of worker.join() > - in worker.stop(), it calls worke

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 2:46 PM, Tarek Ziadé wrote: > here's a very simple demo: http://tarek.pastebin.mozilla.org/1489505 > There are two typos but the effect remains the same since you are locked before you reach those lines: - atexit call worker.stop() instead of worker.join() - in worker.

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 1:43 PM, Antoine Pitrou wrote: > Tarek Ziadé writes: > > > > > > On Tue, Feb 21, 2012 at 10:24 AM, Graham Dumpleton > wrote: > > ... > > > But I don't think you can guarantee that everything is still up in > memory by > > > the time atexit gets called, > > > so you can't

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Antoine Pitrou
Tarek Ziadé writes: > > > On Tue, Feb 21, 2012 at 10:24 AM, Graham Dumpleton wrote: > ... > > But I don't think you can guarantee that everything is still up in memory by > > the time atexit gets called, > > so you can't really call cleanup code there. > The only thing which is done prior to at

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Graham Dumpleton
On 21 February 2012 21:07, Simon Sapin wrote: > Le 21/02/2012 10:31, Graham Dumpleton a écrit : > >> You do realise you are just reinventing context managers? >> >> With this 'application' do requests. > > Indeed. I didn’t want to go too far from the initial "shutdown function" > proposal, but act

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Graham Dumpleton
On 21 February 2012 21:41, Tarek Ziadé wrote: > > > On Tue, Feb 21, 2012 at 10:24 AM, Graham Dumpleton > wrote: >> >> ... >> >> > But I don't think you can guarantee that everything is still up in >> > memory by >> > the time atexit gets called, >> > so you can't really call cleanup code there. >

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 11:07 AM, Simon Sapin wrote: > ... > So a super-set of WSGI that is not just a gateway but also does process > management? > > > @contextlib.contextmanager > def super_application(server_**infos): >with contextlib.closing(open_**resource()) as resource: >wsg

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 10:24 AM, Graham Dumpleton < graham.dumple...@gmail.com> wrote: > ... > > But I don't think you can guarantee that everything is still up in > memory by > > the time atexit gets called, > > so you can't really call cleanup code there. > > The only thing which is done prior

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Simon Sapin
Le 21/02/2012 10:31, Graham Dumpleton a écrit : > You do realise you are just reinventing context managers? > > With this 'application' do requests. Indeed. I didn’t want to go too far from the initial "shutdown function" proposal, but actual context managers would be better. Le 21/02/2012 10

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Simon Sapin
Le 21/02/2012 08:56, Simon Sapin a écrit : Both of these callbacks could be called once per process (aka. space where requests share memory.) Sorry, that should be once per interpreter. -- Simon Sapin ___ Web-SIG mailing list Web-SIG@python.org Web S

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Benoit Chesneau
On Tue, Feb 21, 2012 at 10:35 AM, Sylvain Hellegouarch wrote: > > > On Tue, Feb 21, 2012 at 10:31 AM, Graham Dumpleton > wrote: >> >> On 21 February 2012 20:26, Simon Sapin wrote: >> > Le 21/02/2012 09:23, Tarek Ziadé a écrit : >> > >> >>    Instead of having to provide two or three objects sepa

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Sylvain Hellegouarch
On Tue, Feb 21, 2012 at 10:31 AM, Graham Dumpleton < graham.dumple...@gmail.com> wrote: > On 21 February 2012 20:26, Simon Sapin wrote: > > Le 21/02/2012 09:23, Tarek Ziadé a écrit : > > > >>Instead of having to provide two or three objects separately to a > >>server, how about making the

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Graham Dumpleton
On 21 February 2012 20:26, Simon Sapin wrote: > Le 21/02/2012 09:23, Tarek Ziadé a écrit : > >>    Instead of having to provide two or three objects separately to a >>    server, how about making the callbacks attributes of the application >>    callable? >> >> >> can you show us an example ? > >

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Simon Sapin
Le 21/02/2012 09:23, Tarek Ziadé a écrit : Instead of having to provide two or three objects separately to a server, how about making the callbacks attributes of the application callable? can you show us an example ? Proposal: Function-based: def startup(): return op

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Graham Dumpleton
On 21 February 2012 18:53, Tarek Ziadé wrote: > > > On Tue, Feb 21, 2012 at 2:39 AM, Graham Dumpleton > wrote: >> >> ... >> >> Overall the best chance of being able to do anything is relying on atexit. >> >> You are though at the mercy of the WSGI hosting mechanism shutting >> down the process an

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Benoit Chesneau
On Mon, Feb 20, 2012 at 5:03 PM, Tarek Ziadé wrote: > Hello > > I need to be able to call a function when the web application shuts down > (SIGTERM/SIGINT) -- the use case is to stop a background thread. > > I am currently using signals because it seems to be the most clean way to do > this. atexi

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Sylvain Hellegouarch
> > > Yes, I also think shutting down the server is completely orthogonal to > requests. > > CherryPy is using an approach where, indeed, both are orthogonal. Tools [1], which are similar to middlewares, are dealing with requests whereas the CherryPy engine [2] is the basis upon which the whole ap

Re: [Web-SIG] A 'shutdown' function in WSGI

2012-02-21 Thread Tarek Ziadé
On Tue, Feb 21, 2012 at 8:56 AM, Simon Sapin wrote: > Le 21/02/2012 08:47, Tarek Ziadé a écrit : > > Yes, I also think shutting down the server is completely orthogonal to >> requests. >> > > If the shutdown callback is next to the application and not registered in > a request, why not also have