RE: [Zope] Zope and threads.
Ok, so, this almost completely answers my question. Let me tell you more about what I am doing, because I agree that my initial mail was not that clear. :) I am trying to implement a ZeroConf browser (http://www.zeroconf.org/) in Zope to automatically get the network location of XML RPC services that my Zope objects talk to. The ZMI part is easy. In my new product, I've got my object in the Control Panel, and it is ready to display whatever data I want (for example the list of discovered services). The ZeroConf implementation itself has already been made by someone else (http://sourceforge.net/projects/pyzeroconf) So I am just trying to plug pieces together now :)
From my product, I need to start a thread that will run the ZeroConf code, and ZeroConf data will then be accessible through a particular object of this code (the "listener" to be exact, as they call it in pyzeronf).
This thread should be started when Zope starts, so I guess I can put it in the __init__.py of my product. I only got one issue : my product can be refreshed. So how can I ensure that the ZeroConf stuff won't be re-initialized if I refresh my product ? (ending with 2 threads, with one of the threads not being used). I know this is more a python related question, but I haven't found a precise answer on the net. Thanks for your answers, and sorry that my first mail was unclear. Pascal -----Original Message----- From: Chris McDonough To: Pascal Peregrina Cc: 'zope@zope.org' Sent: 22/02/2005 19:51 Subject: Re: [Zope] Zope and threads. Hi Pascal, It seems like the only thing you need to do is to launch a thread using either the thread or threading module to do what you want if you're not going to access any persistent objects from the newly created thread. Accessing nonpersistent objects created by another thread from within Zope app code is not a problem. - C On Mon, 2005-02-21 at 11:25, Pascal Peregrina wrote:
Hi,
I need to have some processing done in one thread, that will set some attributes of a (non persistent) object. This processing is completely independant from Zope objects.
Zope objects (persistent or non-persistent) will only need to "read" data from this object.
What would be the best way to do this (specially how to initialize my thread ?)
Thanks
Pascal
********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager.
This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com **********************************************************************
______________________________________________________________________ _______________________________________________ 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 )
On Tue, 2005-02-22 at 15:22, Pascal Peregrina wrote:
Ok, so, this almost completely answers my question.
Let me tell you more about what I am doing, because I agree that my initial mail was not that clear. :)
I am trying to implement a ZeroConf browser (http://www.zeroconf.org/) in Zope to automatically get the network location of XML RPC services that my Zope objects talk to.
The ZMI part is easy. In my new product, I've got my object in the Control Panel, and it is ready to display whatever data I want (for example the list of discovered services).
The ZeroConf implementation itself has already been made by someone else (http://sourceforge.net/projects/pyzeroconf)
So I am just trying to plug pieces together now :)
From my product, I need to start a thread that will run the ZeroConf code, and ZeroConf data will then be accessible through a particular object of this code (the "listener" to be exact, as they call it in pyzeronf).
This thread should be started when Zope starts, so I guess I can put it in the __init__.py of my product.
I only got one issue : my product can be refreshed. So how can I ensure that the ZeroConf stuff won't be re-initialized if I refresh my product ? (ending with 2 threads, with one of the threads not being used). I know this is more a python related question, but I haven't found a precise answer on the net.
I'm not sure of how the internals of refresh work (I dont use it) but I suspect that if you do something like: import sys if not getattr(sys, 'ZEROCONF_STARTED'): .. start the thread .. sys.ZEROCONF_STARTED = 1 It will not spawn another thread. "sys" is just an example here, any module namespace should work (even __builtins__ probably).
Pascal Peregrina wrote:
From my product, I need to start a thread that will run the ZeroConf code, and ZeroConf data will then be accessible through a particular object of this code (the "listener" to be exact, as they call it in pyzeronf).
This sounds almost like you want to be running another type of ZServer. Is this the same machine using the "mode_zope" setup though?
I only got one issue : my product can be refreshed.
Well, it really shouldn't be refreshable ;-) Seriously, this is the type of product that falls into the category of "should not be refreshable". Chris provides what amounts to be a hack that might make this work, but Refresh is a hack to stop you having ot restart Zope when you make changes to python code, so two hacks don't makea non-hack, or something... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris McDonough -
Chris Withers -
Pascal Peregrina