RE: [Zope] Using zope as something more than just dynamic webpages
alwyn@smart.com.ph writes:
Is it then possible for example to have pieces of Python code start up when zope start up that will be persistent and executing for as long as zope runs?
I found a rather dirty solution: 1. install a root-cronjob: * * * * * python /pathtopieceofcode/pieceofcode.py 2. pieceofcode.py lokks like: import os,string while 1: noofmyinstances=0 noofzopeinstances=0 for line in os.popen('ps -aux').readlines(): if string.find(line, 'python /pathtopieceofcode/pieceofcode.py')>-1: noofmyinstances+=1 if string.find(line, 'python /pathtozope/z2.py')>-1: noofzopeinstances+=1 if noofzopeinstances==0 or noofmyinstances>1: # the instance counts itself, too break # here comes your piece of code
Look at Zope's database adapters for an example on how to connect to external systems...
Dieter, that sounds interesting but such advice only helps you if you have already reached a rather high level of understanding. I'd like to know how to connect to external systems myself, I looked at ZMySQLDA and now I'm just as stupid as I was before. I see tons of code most of which is not important to my question and I can't find the relevant parts. Horst _________________________________________________________________ Werden Sie Mitglied bei MSN Hotmail, dem größten E-Mail-Service der Welt: http://www.hotmail.com/de
alwyn@smart.com.ph writes:
Is it then possible for example to have pieces of Python code start up when zope start up that will be persistent and executing for as long as zope runs?
If by "executing" you mean "running a loop indefinitely", maybe you could do something like (untested) - make a Product by copying the "Boring" product - in Boring.py (or whatever you call it), add this to the end of __init__(): import time delay_seconds = 1 while 1: # your code goes here time.sleep(delay_seconds) - Add an instance of this product somewhere in your zope tree. Your code should then start running sometime before Zope finishes starting up, and will run as long as Zope is up. It can be disabled by removing the instance of the Product. -- Paul Winkler home: http://www.slinkp.com "Muppet Labs, where the future is made - today!"
On Tuesday 02 Jul 2002 11:03 am, Paul Winkler wrote:
If by "executing" you mean "running a loop indefinitely", maybe you could do something like (untested)
- make a Product by copying the "Boring" product
- in Boring.py (or whatever you call it), add this to the end of __init__():
import time delay_seconds = 1 while 1: # your code goes here time.sleep(delay_seconds)
- Add an instance of this product somewhere in your zope tree.
Your code should then start running sometime before Zope finishes starting up, and will run as long as Zope is up.
With that code, Zope will never finish starting up :-) You need to run that code in its own thread, with the appropriate magic to use yor own ZODB transaction. Take a look at the Xron product, which does exactly this.
On Tue, Jul 02, 2002 at 11:24:14AM +0100, Toby Dickenson wrote:
With that code, Zope will never finish starting up :-)
Erg. Of course. I was engaging in wishful thinking with respect to zope's own threads - which of course have to do with zpublisher, not with starting up zope. Thanks for the clue-stick. -- Paul Winkler home: http://www.slinkp.com "Muppet Labs, where the future is made - today!"
participants (3)
-
horst wald -
Paul Winkler -
Toby Dickenson