Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Make cherrypy.engine not global anymore
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sylvain Hellegouarch  
View profile  
 More options Jun 24, 7:22 am
From: "Sylvain Hellegouarch" <s...@defuze.org>
Date: Wed, 24 Jun 2009 13:22:21 +0200 (CEST)
Local: Wed, Jun 24 2009 7:22 am
Subject: Make cherrypy.engine not global anymore
Hi All,

I've been banging my head around a simple (yet probably not common) use
case where I wanted to fork a process and run a CherryPy instance from
that child process.

I quickly realized that the child process shared (as far as I could tell)
the same cherrypy.engine has its parent, which isn't what I wanted of
course.

I think this is a result of having cherrypy.engine being set to the module
level WSPBus instance in cherrypy.process. This is also the result of
cherrypy various attributes to be set at the module level in
cherrypy.__init__

I was therefore wondering if it wouldn't make some sense to lazily bind
cherrypy.engine and other attributes when accessed for the first time.
Something along:

_engine = None
def setup_engine(bus=None):
    if not bus:
       bus = WSPBus()

    # more initializations

    return bus

def _get_engine():
    if not _engine:
       _engine = setup_engine()
    return _engine

def _set_engine(engine):
    _engine = engine

engine = property(_get_engine, _set_engine)

Now, this snippet is entirely not tested and might break in various ways
but it's to illustrate the idea.

That would also mean we can import other CherryPy sub-packages without the
engine being initialized no matter what.

I often use the cherrypy.process without even setting up a CherryPy
application, hence not even starting cherrypy.engine.

This also means, one could "reset" the engine instance.

Food for thoughts,
- Sylvain

--
Sylvain Hellegouarch
http://www.defuze.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google