On 10/6/06, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> I'm hacking away at a first TG application, and I have a controllers.py
> (in a web created with tg-admin quickstart) that looks like this:
>
> import turbogears
> from turbogears import controllers
> from mimetypes import guess_type
> import os
> import HomePage, \
>         Courses, CourseAll, CourseByCity, CourseByNum, CourseCtForm,
> CourseNmForm, CourseShop, CourseShow, \
>         DeptHome, DeptLinks, DeptStart, DeptPg, \
>         UserEntry
>
> imdict = {}
> txdict = {}
>
> class Root(controllers.RootController, HomePage.Home):
>
>      AllCourses = CourseAll.Page()
>      Course = CourseShow.Page()
>      CourseCity = CourseCtForm.Page()
>      CourseByCity = CourseByCity.Page()
>      CourseNum = CourseNmForm.Page()
>      CourseByNum = CourseByNum.Page()
>      CourseStart = Courses.Page()
>      DeptStart = DeptStart.Page()
>      DeptHome = DeptHome.Page()
>      DeptPgPage = DeptPg.Page()
>      DeptLinks = DeptLinks.Page()
>      NewAccount = UserEntry.Page()
>      CourseEnroll = CourseShop.Enroll()
>      CourseWaitList = CourseShop.WtLst()
>      CourseViewCart = CourseShop.VwCrt()
>      CourseDelBook = CourseShop.DlBk()
>
>      def __init__(self):
>          print "About to initialise the Web.Page ..."
>          HomePage.Home.__init__(self)
>
> The print statement went in because I noticed that some messages
> appeared to be duplicated when I started the server. I then modified the
> head of the HomePage module to print out a few details, as it appeared
> to be running twice. It now starts like this:
>
> print "IMPORTING HomePage as ", __name__
> import sys, threading
> print "Actiev threads:", threading.activeCount()
> if sys.modules['__main__'].importcount >0 : raise NotImplementedError
> sys.modules['__main__'].importcount += 1
>
> The start program has only had a statement
>
> importcount = 0
>
>
> inserted. Now when I start up my app I see the following:
>
> C:\Steve\Projects\gs>python start-gs.py
> IMPORTING HomePage as  HomePage
> Actiev threads: 1
> IMPORTING Dept
> IMPORTING DeptStart
> About to initialise the Web.Page ...
> IMPORTING HomePage as  HomePage
> Actiev threads: 1
> IMPORTING Dept
> IMPORTING DeptStart
> About to initialise the Web.Page ...
> 2006-10-06 17:14:42,977 cherrypy.msg INFO CONFIG: Server parameters:
>
> So, my question is, how come the HomePage module (along with various
> others) is being executed twice? When I hit CTRL/C to terminate the
> server I also see
>
> 2006-10-06 17:15:40,930 cherrypy.msg INFO ENGINE: <Ctrl-C> hit: shutting
> down au
> toreloader
> 2006-10-06 17:15:40,940 cherrypy.msg INFO HTTP: HTTP Server shut down
> 2006-10-06 17:15:40,950 cherrypy.msg INFO ENGINE: CherryPy shut down
> 2006-10-06 17:15:41,171 cherrypy.msg INFO ENGINE: <Ctrl-C> hit: shutting
> down au
> toreloader
> 2006-10-06 17:15:41,171 cherrypy.msg INFO HTTP: HTTP Server shut down
> 2006-10-06 17:15:41,181 cherrypy.msg INFO ENGINE: CherryPy shut down
>
> What gives?

The autoreloader starts your app in a subprocess, so it can kill it
and then start it up again.

You're just looking at interleaved output between two different
processes that have both imported your module. Only one of them is
going to actually use it with CherryPy though.

-bob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to