[Zope] Running a script at Zope startup

Herman Geldenhuys hgeldenhuys@gmsonline.co.za
Mon, 28 Jul 2003 14:30:44 +0200


You see, I rarely ever access the connection from within Zope itself. The
client connection must always be there when Zope is up and running. The
client has callback methods registered on the remote server-prior to Zope's
startup.The server sends an event to the client connection. I think it would
be easier to understand if we change the client connection to a "server"
running on a certain port inside of one of Zope's objects. The server is
first created in the __init__ of the proxy object, and is expected to always
be there... The crux of this situation is that the connection is supposed to
be persistent, and cannot be created after accessing the connection object
from within Zope.

class myFancyProxy:
    def __init__(self, address, reports):
        self._address = address
        self._v_connection = ClientConn(address)
        self._v_connection.subscribeToReports(reports, self.callback)
    def callback(self, report):
        ...
    def ???onstartup???(self):
        self._v_connection = ClientConn(self._address)
        self._v_connection.subscribeToReports(reports, self.callback)

Thanks again

Herman


Lbh pna'g gehfg lbhe rlrf vs lbhe vzntvangvba'f bhg bs sbphf. -Znex Gjnva
----- Original Message -----
From: "Tino Wildenhain" <tino@wildenhain.de>
To: "Herman Geldenhuys" <hgeldenhuys@gmsonline.co.za>
Cc: <zope@zope.org>
Sent: Monday, July 28, 2003 4:29 PM
Subject: Re: [Zope] Running a script at Zope startup


>
>
> > ----------
> > From: Tino Wildenhain[SMTP:TINO@WILDENHAIN.DE]
> > Sent: Monday, July 28, 2003 4:29:02 PM
> > To: Herman Geldenhuys
> > Cc: zope@zope.org
> > Subject: Re: [Zope] Running a script at Zope startup
> > Auto forwarded by a Rule
> >
> Hi,
>
> Herman Geldenhuys wrote:
> > Thanks Tino!
> >
> > I understand that I need to initialize a _v_ attribute each time I
create my
> > client connection, seeing that it cannot be stored in the ZODB. My
problem
> > is that I need a way to initiate that attribute at Zope's startup. Lets
say
> > that there are certain ZOPE objects in the hierarchy of ZOPE. I need to
> > initialize all these objects _v_clientConnection attributes at Zope's
> > startup. Does anybody know of a way?
>
> Why on startup? You have to instantiate it on each thread which
> is created. Why not just make the connection as soon as a method
> is called on the object?
>
> Imagine your object might be not actually loaded from ZODB on
> Zopes startup.
>
> something like:
>
> class myFancyProxy:
> def __init__(self,id,proxyparams):
> self.id=id
> self.proxyparams=proxyparams
>
> def doSomething(self,args):
> if not hasattr(self,'_v_connection'):
> self.connect()
> self._v_connection.doSomething(args)
> def connect(self)
> self._v_connection=createConnectionSomeHow(self.proxyparams)
>
>
>
> (Just a rough outline!)
>
> HTH
> Tino
>
> >
> > Thanks
> >
> > Herman
> >
> > ----- Original Message -----
> > From: "Tino Wildenhain" <tino@wildenhain.de>
> > To: "Herman Geldenhuys" <hgeldenhuys@gmsonline.co.za>
> > Cc: <zope@zope.org>
> > Sent: Monday, July 28, 2003 9:35 AM
> > Subject: Re: [Zope] Running a script at Zope startup
> >
> >
> >
> >>
> >>>----------
> >>>From: Tino Wildenhain[SMTP:TINO@WILDENHAIN.DE]
> >>>Sent: Monday, July 28, 2003 9:35:19 AM
> >>>To: Herman Geldenhuys
> >>>Cc: zope@zope.org
> >>>Subject: Re: [Zope] Running a script at Zope startup
> >>>Auto forwarded by a Rule
> >>>
> >>
> >>Hi Herman,
> >>
> >>Herman Geldenhuys wrote:
> >>
> >>>EmailHi all!
> >>>
> >>>I have searched for a sollution, but could not find an appropriate way
> >
> > to
> >
> >>>execute a python script when Zope starts up.
> >>>
> >>>Does anybody know of a way that I am able to do this? What I basically
> >
> > have,
> >
> >>>is client objects residing inside Zope objects, that needs to connect
to
> >>>remote servers each time zope starts up. The client connections cannot
> >>>persist in the ZODB, so I need to create them each time. The zope
> >
> > objects in
> >
> >>>this instance acts only as a proxy-type object.
> >>
> >>A common way to do this not at start up but soon as the object
> >>is needed. Thats the way most DB adaptors do it.
> >>Search for _v_* volatile attributes for a start.
> >>
> >>HTH
> >>Tino Wildenhain
> >>
> >>
> >>_______________________________________________
> >>Zope maillist  -  Zope@zope.org
> >>http://mail.zope.org/mailman/listinfo/zope
> >>**   No cross posts or HTML encoding!  **
> >>(Related lists -
> >> http://mail.zope.org/mailman/listinfo/zope-announce
> >> http://mail.zope.org/mailman/listinfo/zope-dev )
> >>
> >
> >
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://mail.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://mail.zope.org/mailman/listinfo/zope-announce
> >  http://mail.zope.org/mailman/listinfo/zope-dev )
> >
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>