List Info

Thread: Re: cherrypy 3.0.1, lighttpd and fcgi through flup stop problem




Re: cherrypy 3.0.1, lighttpd and fcgi through flup stop problem
country flaguser name
United States
2007-06-01 11:22:52
asmodai wrote:
> On May 30, 11:50 pm, "Robert Brewer"
<fuman...amor.org> wrote:
> > The problem is most likely that your WSGI server
is starting its own
> > threads, but CP doesn't know how to tell it to
shut down 
> those threads.
> > Ideally, you'd write a very small adapter so that,
when the 
> SIGTERM is
> > handled, cherrypy.server (really a server manager)
will send a stop
> > message to the flup.server.fcgi.WSGIServer. See
> > 
http://www.cherrypy.org/wiki/ServerAPI#HTTPServerAPI for
a 
> discussion of
> > what that adapter layer needs to look like.
> 
> Reading that URL and looking at my setup, I do not
think it matches.
> Lighttpd is the one spawning the fcgi process which in
turn starts up
> cherrypy. Cherrypy is not the process in command and as
such is not
> the one in need to send the stop. Lighttpd sends flup a
SIGTERM, flup
> then starts to tear down the process and clean up the
socket.
> 
> I suddenly realised the solution was fairly simple and
I tested this
> with the stop/start cycle of lighttpd as well as a
restart:
> 
> import cherrypy
> import os
> 
> from flup.server.fcgi import WSGIServer
> 
> from kouyou.controllers import *
> 
> current_dir =
os.path.dirname(os.path.abspath(__file__))
> 
> dispatcher = cherrypy.dispatch.RoutesDispatcher()
> dispatcher.connect('home', '',
controller=HomeController())
> 
> config = {'/': {'request.dispatch': dispatcher,
>                 'tools.staticdir.root':
os.path.join(current_dir,
> 'static')},
>           '/css': {'tools.staticdir.on': True,
>                    'tools.staticdir.dir': 'css'},
>           '/img': {'tools.staticdir.on': True,
>                    'tools.staticdir.dir': 'img'}
>          }
> 
> 
> app = cherrypy.tree.mount(None, config=config)
> cherrypy.engine.start(blocking=False)
> try:
>     try:
>         WSGIServer(app).run()
>     except SystemExit:
>         raise
>     except Exception, e:
>         print 'Content-Type: text/plainrnrn',
>         print 'Oops...'
>         print
>         print 'Kouyou detected an internal error:'
>         print
>         print e
>         print
>         import traceback
>         import StringIO
>         tb = StringIO.StringIO()
>         traceback.print_exc(file=tb)
>         print tb.getvalue()
> finally:
>     cherrypy.engine.stop()
> 
> Comments/ideas/opinions?

Aha. I hadn't correctly read your initial post; I didn't
realize you
weren't using cherrypy.server.start in the first place.

So; your solution looks fine, except for all those print
statements...what's stdout at that point? Don't tell me that
whole
script is run once per request!


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: cherrypy 3.0.1, lighttpd and fcgi through flup stop problem
country flaguser name
United States
2007-06-01 14:42:16
On Jun 1, 6:22 pm, "Robert Brewer"
<fuman...amor.org> wrote:
> So; your solution looks fine, except for all those
print
> statements...what's stdout at that point? Don't tell me
that whole
> script is run once per request!

It should be towards the webserver, which then serves it to
the
client.

And for all I know it does not run that script once per
request. The
fastcgi socket is created on webserver start:

[19:37] [asmodainexus] (506)  % sockstat | grep labs
www      python     955   0  stream /tmp/labs.sock-0
www      python     955   3  stream /tmp/labs.sock-0

Which equates to

PID USERNAME   THR PRI NICE   SIZE    RES STATE  C   TIME  
WCPU
COMMAND
955 www         10  20    0 12216K  9044K kserel 0   0:51 
0.00%
python

So it spawns one process which has 10 threads and that's all
handing
off incoming data for this host to the cherrypy code. So all
in all
quite efficient from what I can tell.

--
Jeroen Ruigrok van der Werven
<asmodai(-at-)in-nomine.org> / asmodai
イェルーン ラウフロック ヴァン デル
ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
The Wheels of Life, they turn, ..., without me...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )