moment when zope was started.
Hello zope-dev! How could i find the moment when zope was started in Zope 2.8? in Zope 2.7 was the variable 'Zope.Startup.started', which setted to True when zope was started. But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to True, because Zope2.Startup.start_zope was never called, instead of that called Zope2.Startup.run.run function. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Victor Safronovich wrote:
But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to True, because Zope2.Startup.start_zope was never called, instead of that called Zope2.Startup.run.run function.
This sounds like a bug, but why do you want to know this? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Hello Chris Withers, Monday, November 7, 2005, 8:15:58 PM, you wrote: CW> Victor Safronovich wrote:
But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to True, because Zope2.Startup.start_zope was never called, instead of that called Zope2.Startup.run.run function.
CW> This sounds like a bug, but why do you want to know this? My Product wants to replace zpublisher_validate_hook in Zope2.__init__. Formerly I use the code class ZPValidateHookReplacer(Thread): def run(self): while not Zope.Startup.started: # in 2.8 'Zope' module must be replaced to Zope2 time.sleep(0.5) Zope.zpublisher_validate_hook = my_validate_hook ZPValidateHookReplacer().start() in Zope 2.8 this code was broken because Zope.Startup.started always False. I changed to new repeat condition "while Zope.zpublisher_validate_hook is None: time.sleep(0.5)" But what if others use Zope.Startup.started variable? -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Victor Safronovich wrote:
My Product wants to replace zpublisher_validate_hook in Zope2.__init__.
Why on earth would you want to do that?! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Hello Chris Withers, Tuesday, November 8, 2005, 1:26:29 PM, you wrote: CW> Why on earth would you want to do that?! :) my product needs to do some specific things, right after the user is authenticated and becomes known. hook is hook and it may be overloaded as with zpublisher_exception_hook. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Victor Safronovich schrieb:
Hello Chris Withers,
Tuesday, November 8, 2005, 1:26:29 PM, you wrote:
CW> Why on earth would you want to do that?! :) my product needs to do some specific things, right after the user is authenticated and becomes known. hook is hook and it may be overloaded as with zpublisher_exception_hook.
You might want to look at userfolder implementation, for example PAS.
Hello Tino Wildenhain, Tuesday, November 8, 2005, 4:29:39 PM, you wrote: TW> You might want to look at userfolder implementation, for example PAS. Thank you, i look at it, but this is another story ;). -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Victor Safronovich schrieb:
Hello Tino Wildenhain,
Tuesday, November 8, 2005, 4:29:39 PM, you wrote:
TW> You might want to look at userfolder implementation, for example PAS. Thank you, i look at it, but this is another story ;).
Now you should tell us what you are really doing here :-)
Hello Tino Wildenhain, Tuesday, November 8, 2005, 5:56:25 PM, you wrote: TW> Now you should tell us what you are really doing here :-) Subject: Re: [Zope-dev] moment when zope was started. /\ want to know | -------------------------/ -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
On 11/8/05, Victor Safronovich <vsafronovich@naumen.ru> wrote:
Hello Tino Wildenhain,
Tuesday, November 8, 2005, 5:56:25 PM, you wrote:
TW> Now you should tell us what you are really doing here :-) Subject: Re: [Zope-dev] moment when zope was started. /\ want to know |
Yeah, but he asked for what you are trying to do, not what you want to know. We can't help you if we don't know what you are trying to do.
Hello Lennart Regebro, Tuesday, November 8, 2005, 6:43:23 PM, you wrote: LR> Yeah, but he asked for what you are trying to do, not what you want to LR> know. We can't help you if we don't know what you are trying to do. Ok, i need to replace zpublisher_validate_hook with my hook. my hook: def zpublisher_validated_hook( REQUEST, user ): Zope._nau_zpublisher_validated_hook( REQUEST, user ) # old validate hook published = self.PUBLISHED published = getattr(published, 'im_self', published) portal = published.getPortalObject() if hasattr( portal, '_afterValidateHook' ): portal._afterValidateHook( user, published, REQUEST ) _afterValidateHook do many thinks specific to the portal such as 1. Sets response charset according to the user's selected language. 2. Replaces HTML-encoded entities with their corresponding characters in the POST form data. 3. Changes system locale according to the portal language. Ok, 2. and 3. can be moved to UserFolder.validate method, which PAS used. But 1. uses getSecurityManager through Products.CMFCore.utils._getAuthenticatedUser through MembershipTool.{isAnonymousUser,getAuthenticatedMember}, and must be executed after the Zope`s zpublisher_validate_hook hook, which setted new security manager. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
On 11/9/05, Victor Safronovich <vsafronovich@naumen.ru> wrote:
Ok, i need to replace zpublisher_validate_hook with my hook. [...] _afterValidateHook do many thinks specific to the portal such as 1. Sets response charset according to the user's selected language. 2. Replaces HTML-encoded entities with their corresponding characters in the POST form data. 3. Changes system locale according to the portal language.
Ok, 2. and 3. can be moved to UserFolder.validate method, which PAS used. But 1. uses getSecurityManager through Products.CMFCore.utils._getAuthenticatedUser through MembershipTool.{isAnonymousUser,getAuthenticatedMember}, and must be executed after the Zope`s zpublisher_validate_hook hook, which setted new security manager.
OK, fine, I don't know if there is another way of doing this, so I'll assume your way is the best (although it's complicated). But you say you want to know when the server was started. How does that come into any of the above things? None of those have anything to do with how long the server has been running. You are just giving us small disassociated pieces of information, and then you assume that we should read your mind for the rest of the needed information. It doesn't work like that. http://www.catb.org/~esr/faqs/smart-questions.html -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/
Victor Safronovich wrote:
_afterValidateHook do many thinks specific to the portal such as 1. Sets response charset according to the user's selected language.
Why not just do this is a normal traversal hook such as an access rule?
2. Replaces HTML-encoded entities with their corresponding characters in the POST form data.
Incomign POST form data? Why not just munge the data when you get it from the request in your application?
3. Changes system locale according to the portal language.
Can be done in an access rule... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
VS> How could i find the moment when zope was started in Zope 2.8? VS> in Zope 2.7 was the variable 'Zope.Startup.started', which setted to True when VS> zope was started. VS> But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to VS> True, because Zope2.Startup.start_zope was never called, instead of that called VS> Zope2.Startup.run.run function. this may be fixed like in attachment. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
If you go to the control panel of a running Zope, you'll see it display "Running For" with the correct number of seconds. So there's obviously an existing way for the server to know when it was started, just look how the control panel does it. Florent Victor Safronovich wrote:
VS> How could i find the moment when zope was started in Zope 2.8? VS> in Zope 2.7 was the variable 'Zope.Startup.started', which setted to True when VS> zope was started.
VS> But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to VS> True, because Zope2.Startup.start_zope was never called, instead of that called VS> Zope2.Startup.run.run function. this may be fixed like in attachment.
------------------------------------------------------------------------
Index: __init__.py =================================================================== --- __init__.py (revision 39858) +++ __init__.py (working copy) @@ -28,13 +28,17 @@
logger = logging.getLogger("Zope") started = False +starter = None
def get_starter(): - check_python_version() - if sys.platform[:3].lower() == "win": - return WindowsZopeStarter() - else: - return UnixZopeStarter() + global starter + if starter is None: + check_python_version() + if sys.platform[:3].lower() == "win": + starter = WindowsZopeStarter() + else: + starter = UnixZopeStarter() + return starter
def start_zope(cfg, debug_handler): """The function called by run.py which starts a Zope appserver.""" @@ -47,11 +51,11 @@ starter.setConfiguration(cfg) starter.prepare()
- started = True + starter.start() try: starter.run() finally: - started = False + starter.finish()
class ZopeStarter: @@ -59,6 +63,8 @@
Making it a class makes it easier to test. """ + started = False + def __init__(self): self.event_logger = logging.getLogger() # We log events to the root logger, which is backed by a @@ -81,6 +87,14 @@ def setConfiguration(self, cfg): self.cfg = cfg
+ def start(self): + global started + self.started = started = True + + def finish(self) + global started + self.started = started = False + def prepare(self): self.setupInitialLogging() self.setupLocale() Index: run.py =================================================================== --- run.py (revision 39858) +++ run.py (working copy) @@ -15,11 +15,7 @@ def run(): """ Start a Zope instance """ import Zope2.Startup - starter = Zope2.Startup.get_starter() - opts = _setconfig() - starter.setConfiguration(opts.configroot) - starter.prepare() - starter.run() + Zope2.Startup.start_zope(_setconfig().configroot, None)
def configure(configfile): """ Provide an API which allows scripts like zopectl to configure
------------------------------------------------------------------------
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
-- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
Hello Florent Guillaume and , Wednesday, November 9, 2005, 3:54:26 PM, you wrote: FG> If you go to the control panel of a running Zope, you'll see it display FG> "Running For" with the correct number of seconds. So there's obviously an FG> existing way for the server to know when it was started, just look how the FG> control panel does it. Thank you, looks like the initialization time of the App.ApplicationManager.ApplicationManager class. Hello Lennart Regebro, Wednesday, November 9, 2005, 3:55:57 PM, you wrote: LR> But you say you want to know when the server was started. How does LR> that come into any of the above things? None of those have anything to LR> do with how long the server has been running. LR> You are just giving us small disassociated pieces of information, and LR> then you assume that we should read your mind for the rest of the LR> needed information. It doesn't work like that. LR> http://www.catb.org/~esr/faqs/smart-questions.html Thank you for the url, and sorry for my english, I just want to say that variable 'Zope2.Startup.started' is always False. This variable is used for example here http://cvs.sourceforge.net/viewcvs.py/mailmanager/mailmanager/MailCheckThrea... some times ago. But now this is deleted file. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Victor Safronovich wrote:
Hello zope-dev!
How could i find the moment when zope was started in Zope 2.8? in Zope 2.7 was the variable 'Zope.Startup.started', which setted to True when zope was started.
But in Zope 2.8 the variable 'Zope2.Startup.started' not changed its value to True, because Zope2.Startup.start_zope was never called, instead of that called Zope2.Startup.run.run function.
What do you suggest? If you feel the attribute 'started' should be removed from Zope, because it's unused, please file a new ticket in the Zope collector. Florent -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
Hello Florent Guillaume, Wednesday, November 9, 2005, 6:09:29 PM, you wrote: FG> What do you suggest? If you feel the attribute 'started' should be removed FG> from Zope, because it's unused, please file a new ticket in the Zope collector. I suggest that variable `started` is usefull. Even more i think the instance `starter` of the Zope2.Startup.ZopeStarter class should be sigleton and placed in its module ( to get it from other places), and the variable 'started' should be the attribute of this singleton ( may be `Starter` rename to `ZopeMainThread` ). And ZopeStarter`s methods should use its instance more. -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
Hello Florent Guillaume, Wednesday, November 9, 2005, 6:09:29 PM, you wrote: FG> What do you suggest? If you feel the attribute 'started' should be removed FG> from Zope, because it's unused, please file a new ticket in the Zope collector. I think out, `Starter` has 2 Events( threading.Event ) startEvent and finishEvent, `Starter` manages this events ( sets its flag ) all others Threads may use this events for example (not tested), the code below may be usefull for somebody from SomeWhere import Starter as ZopeMainThread from threading import Thread class MyStartThread(Thread): def __init__(self): Thread.__init__(self) self.setDaemon(1) def run(self): ZopeMainThread.startEvent.wait() # wait for start zope, but may be # this eat processor resources #do_something_at_start MyStartThread().start() class MyFinishThread(Thread): def __init__(self): Thread.__init__(self) self.setDaemon(1) def run(self): ZopeMainThread.finishEvent.wait() # wait for stop zope #do_something_at_finish() MyFinishThread().start() -- Best regards, Victor Safronovich NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
participants (5)
-
Chris Withers -
Florent Guillaume -
Lennart Regebro -
Tino Wildenhain -
Victor Safronovich