Running a script at Zope startup
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. Thanks H
Herman Geldenhuys wrote at 2003-7-25 15:35 +0200:
...
There is a product called "StartupScripts" that may do what you want. It is an old product (do not know whether it is still maintained). It may not work with modern Zope versions. However, it is a good starting point anyway... Dieter
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
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? 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 )
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?
I have not followed the thread, so I may be missing something, but I think that Tino's answer is right. You may achieve this defining a getter method, something like: def get_client_connection(self) : if not hasattr(self, "_v_clientConnection") : self._v_clientConnection = xxxxx return sef._v_clientConnection if you access this attribute through the method, and never directly, you'll always get a "valid" client connection. HTH -- //// (@ @) ---------------------------oOO----(_)----OOo------------------------ Los pecados de los tres mundos desapareceran conmigo. Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) --------------------------------------------------------------------
Hi My problem is that the client connection must be started as soon as Zope starts up. Ie, the attribute must be initialized prior to accessing it from within the Zope context. As soon as Zope starts, my client connection must be made, so that the remote server via a persistent connection to the client, can invoke callback methods when an event occurs on the server's side. So, the connection attribute is rarely ever called from within the same "process". Is'nt there a "startup" event for Zope(event indication all modules are finished loaded)? Thanks again. Herman Lbh pna'g gehfg lbhe rlrf vs lbhe vzntvangvba'f bhg bs sbphf. -Znex Gjnva ----- Original Message ----- From: "Alexis Roda" <arv@si.urv.es> To: "Herman Geldenhuys" <hgeldenhuys@gmsonline.co.za> Cc: "zope" <zope@zope.org> Sent: Monday, July 28, 2003 1:57 PM Subject: Re: [Zope] Running a script at Zope startup
---------- From: Alexis Roda[SMTP:ARV@SI.URV.ES] Sent: Monday, July 28, 2003 1:57:09 PM To: Herman Geldenhuys Cc: zope Subject: Re: [Zope] Running a script at Zope startup Auto forwarded by a Rule
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?
I have not followed the thread, so I may be missing something, but I think that Tino's answer is right. You may achieve this defining a getter method, something like:
def get_client_connection(self) : if not hasattr(self, "_v_clientConnection") : self._v_clientConnection = xxxxx return sef._v_clientConnection
if you access this attribute through the method, and never directly, you'll always get a "valid" client connection.
HTH -- //// (@ @) ---------------------------oOO----(_)----OOo------------------------ Los pecados de los tres mundos desapareceran conmigo. Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) --------------------------------------------------------------------
_______________________________________________ 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 )
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 )
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 )
participants (4)
-
Alexis Roda -
Dieter Maurer -
Herman Geldenhuys -
Tino Wildenhain