Using CherryPy locally and launching a browser

151 views
Skip to first unread message

Andre

unread,
Apr 29, 2006, 12:23:24 PM4/29/06
to cherrypy-users
First of all, I would like to congratulate CherryPy developpers. It's
really user friendly. I downloaded it last night and, without any
prior web programming experience, I managed to get it to do something
useful for me!

I am using CherryPy to create a kind of Python Console run locally.
Although it is not required to answer my question, if you want more
detail of what I mean by this, you can read
http://aroberge.blogspot.com/2006/04/cherrypy-is-great.html
Eventually I intend to use this type of web-browser environment as a
graphical front-end for "rur-ple".

As I start CherryPy, I want to start my browser automatically. I do
this (schematically) as follows:

=====
import webbrowser
import cherrypy

settings = {
'global': {
'server.socketPort' : 8080,
'server.threadPool': 10,
'server.environment': "production"
}
class PythonRunner(object):
def index(self):
return ''
index.exposed = True

cherrypy.root = PythonRunner()
cherrypy.config.update({'session_filter.on': True})
webbrowser.open('http://localhost:8080/index')

if __name__ == '__main__':
cherrypy.config.update(settings)
cherrypy.server.start()
===========
If I don't have a webbrowser (read "Firefox") running, it loads it up
just fine.
If Firefox is already running, then a new tab gets open *but* I get an
error message as the connection is not established; to make it work, I
have to reload the page.
I was wondering if there was a way to find out if the server is running
properly before opening the webbrowser connection. I'd rather not put
an artificial time delay if I can avoid it.

André

Robert Brewer

unread,
Apr 29, 2006, 2:35:19 PM4/29/06
to cherrypy-users

Andre wrote:
> http://aroberge.blogspot.com/2006/04/cherrypy-is-great.html
> Eventually I intend to use this type of web-browser
> environment as a graphical front-end for "rur-ple".

You might want to take a look at HTTPREPL, which gives you a "Python prompt" in your browser. Unfortunately, you can't look at it right now, because our firewall had a meltdown yesterday. :( Try on Monday or Tuesday.
http://projects.amor.org/misc/wiki/HTTPREPL



> As I start CherryPy, I want to start my browser automatically.

> ...


> I was wondering if there was a way to find out if the server
> is running properly before opening the webbrowser connection.
> I'd rather not put an artificial time delay if I can avoid it.

Yes. As Christian Wyglendowski pointed out (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481) you can use start_with_callback:

    cherrypy.server.start_with_callback(
        webbrowser.open, ('http://localhost:8080',) )


Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org

Andre

unread,
Apr 29, 2006, 2:58:47 PM4/29/06
to cherrypy-users
Robert Brewer wrote:
> Andre wrote:
> > http://aroberge.blogspot.com/2006/04/cherrypy-is-great.html
> > Eventually I intend to use this type of web-browser
> > environment as a graphical front-end for "rur-ple".
>
> You might want to take a look at HTTPREPL, which gives you a "Python prompt" in your browser. Unfortunately, you can't look at it right now, because our firewall had a meltdown yesterday. :( Try on Monday or Tuesday.
> http://projects.amor.org/misc/wiki/HTTPREPL
>

Will do.

> > As I start CherryPy, I want to start my browser automatically.
> > ...
> > I was wondering if there was a way to find out if the server
> > is running properly before opening the webbrowser connection.
> > I'd rather not put an artificial time delay if I can avoid it.
>
> Yes. As Christian Wyglendowski pointed out (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481) you can use start_with_callback:
>
> cherrypy.server.start_with_callback(
> webbrowser.open, ('http://localhost:8080',) )
>

Thank you, that worked perfectly!
André

>
> Robert Brewer

Reply all
Reply to author
Forward
0 new messages