[Twisted-Python] Twisted apps + zeroconf, anyone?
![](https://secure.gravatar.com/avatar/b2240245799c094c7d834c4dc2cf2b48.jpg?s=120&d=mm&r=g)
I'd like to add auto-discovery feature to my (Twisted) application and I thought I'll use zeroconf to advertize the service to clients in local network. I decided on zeroconf, because the app is a webservice that has to be accessible to multitude of various clients. Unfortunately, the only one library I found barely usable with Twisted is PyZeroconf (the other is avahi, but it seems too tightly bound to gobject to be usable with Twisted). Is this all or I do not know how to use google? Anybody can share any hints on this? Is this feasible idea or there are better ways to achieve what I want? Cheers Jarek Zgoda
![](https://secure.gravatar.com/avatar/79b398e90ee81bd64ec95da03c16f36c.jpg?s=120&d=mm&r=g)
Jarek Zgoda a écrit :
A quick search of twisted and zeroconf should redirect you to some infos, especially to the mDNS implementation of itamar in its sandbox: http://twistedmatrix.com/trac/browser/sandbox/itamar/mdns. Nothing completly finished though, but contributions are welcome :). I don't know avahi, but the fact it uses gobject may not be a problem if you use the gtk2reactor. -- Thomas
![](https://secure.gravatar.com/avatar/b2240245799c094c7d834c4dc2cf2b48.jpg?s=120&d=mm&r=g)
Thomas Hervé <therve@free.fr> napisał(a):
Did not notice this one, thank you. From the quick view, it seems like the whole service publishing part is not yet implemented. I never wrote any line of code "Twisted style", maybe this will be my first time. ;)
I don't know avahi, but the fact it uses gobject may not be a problem if you use the gtk2reactor.
Actually, this is a REST webservice built upon twisted.web. Registering service using avahi requires async DBus connection and, effectively, gobject main loop. This does not seem to be good choice for service that is supposed to serve hundreds of requests per minute... Cheers Jarek Zgoda
![](https://secure.gravatar.com/avatar/450aeb9ce64675fb7eb9c08f0b271215.jpg?s=120&d=mm&r=g)
On Wed, Dec 26, 2007 at 08:56:39PM +0100, Jarek Zgoda wrote:
I use avahi with the glib2reactor on a high traffic system and it works pretty good for me. The service is only registered once at startup, and service discovery is done by simply connecting to DBus signal. Everything only with a few lines of code :) So long :wq buz -- There are two major products to come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. GnuPG Fingerprint: 2FFF FC48 C7DF 1EA0 00A0 FD53 8C35 FD2E 6908 7B82
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Wed, 26 Dec 2007 13:31:50 +0100, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
There is only supposed to be one process on a system taking care of zeroconf publications. This means that it is more likely that you will want your app to talk to some existing zeroconf software. For example, on Linux, avahi. This means that for most practical purposes, you don't actually want to talk mdns. You want to talk to avahi (or to something on OS X, or to something on Windows). This doesn't mean it wouldn't be cool to have a very Twisted-friendly zero- conf library. But it does mean that for practical purposes, that's usually not what you want. Jean-Paul
![](https://secure.gravatar.com/avatar/b2240245799c094c7d834c4dc2cf2b48.jpg?s=120&d=mm&r=g)
Jean-Paul Calderone napisał(a):
I do not want to run my own mDNS service, I just want to advertize (publish) my webservice in running instance of mDNS. I think it would be Avahi mDNS/SD in most cases, but I cann't be sure now. The PyZeroconf library has many global state objects so I think it's not well suited for any forking environment. Python-avahi looks far better, but it requires gobject-based main loop to be used asynchronously (other way it can not connect to DBus signals). Itamar's module (mentioned by Thomas) seems to be perfect fit my needs if only I'd be able to implement service publishing part (discovery and browsing works well, after adapting the code to Twisted 2.5 layout). ;) -- Jarek Zgoda Skype: jzgoda | GTalk: zgoda@jabber.aster.pl | voice: +48228430101 "We read Knuth so you don't have to." (Tim Peters)
![](https://secure.gravatar.com/avatar/42148ea9c50179d54c77987a998af7a0.jpg?s=120&d=mm&r=g)
A while back I implemented a wrapper around pyzeroconf that integrated it into the twisted event loop. While we never did anything with this, it seemed to work fine. The design is not wonderful, but it does show how everything can be done. Here it is: http://projects.scipy.org/ipython/ipython/browser/ipython/sandbox/bgranger/b... At some point we might end up using this - let us know if it is helpful or worth putting somewhere more public. Brian On Dec 26, 2007 5:31 AM, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
![](https://secure.gravatar.com/avatar/769326b856fc9c7ef80a425fecd05ac9.jpg?s=120&d=mm&r=g)
On 12/26/07, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
we just used the Apple Rendezous code, it has a python wrapper around its C code. it is available for free from Apple's developer website. We had it in production for 2 years without a single hicup or restart.
![](https://secure.gravatar.com/avatar/3420ca67c72ac7c6674a4a980c3087d3.jpg?s=120&d=mm&r=g)
I've recently run into this issue as well Jarek. The easiest solution I found was to just launch a background 'avahi-publish' subprocess with the appropriate arguments. Send it a friendly kill signal when you wish to stop publishing and that's the end of it. It's a linux-specific solution, of course, but it's dirt simple and avoids the problem of multiple-mdns stacks on a single machine. If you'd like to support other platforms and/or non-avahi mdns stacks, it should be fairly straight-forward to write a small C/Python application for each that does the effectively the same thing. Likewise, for browsing services, I've decided to go the route of using 'avahi-browse' to extract the information for me rather than try and re-implement it directly in Python. Python is so damn friendly, I often forget that good ol' shell commands can often be the best tool for the job ;-) Cheers, Tom On Dec 26, 2007 7:31 AM, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
![](https://secure.gravatar.com/avatar/79b398e90ee81bd64ec95da03c16f36c.jpg?s=120&d=mm&r=g)
Jarek Zgoda a écrit :
A quick search of twisted and zeroconf should redirect you to some infos, especially to the mDNS implementation of itamar in its sandbox: http://twistedmatrix.com/trac/browser/sandbox/itamar/mdns. Nothing completly finished though, but contributions are welcome :). I don't know avahi, but the fact it uses gobject may not be a problem if you use the gtk2reactor. -- Thomas
![](https://secure.gravatar.com/avatar/b2240245799c094c7d834c4dc2cf2b48.jpg?s=120&d=mm&r=g)
Thomas Hervé <therve@free.fr> napisał(a):
Did not notice this one, thank you. From the quick view, it seems like the whole service publishing part is not yet implemented. I never wrote any line of code "Twisted style", maybe this will be my first time. ;)
I don't know avahi, but the fact it uses gobject may not be a problem if you use the gtk2reactor.
Actually, this is a REST webservice built upon twisted.web. Registering service using avahi requires async DBus connection and, effectively, gobject main loop. This does not seem to be good choice for service that is supposed to serve hundreds of requests per minute... Cheers Jarek Zgoda
![](https://secure.gravatar.com/avatar/450aeb9ce64675fb7eb9c08f0b271215.jpg?s=120&d=mm&r=g)
On Wed, Dec 26, 2007 at 08:56:39PM +0100, Jarek Zgoda wrote:
I use avahi with the glib2reactor on a high traffic system and it works pretty good for me. The service is only registered once at startup, and service discovery is done by simply connecting to DBus signal. Everything only with a few lines of code :) So long :wq buz -- There are two major products to come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. GnuPG Fingerprint: 2FFF FC48 C7DF 1EA0 00A0 FD53 8C35 FD2E 6908 7B82
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Wed, 26 Dec 2007 13:31:50 +0100, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
There is only supposed to be one process on a system taking care of zeroconf publications. This means that it is more likely that you will want your app to talk to some existing zeroconf software. For example, on Linux, avahi. This means that for most practical purposes, you don't actually want to talk mdns. You want to talk to avahi (or to something on OS X, or to something on Windows). This doesn't mean it wouldn't be cool to have a very Twisted-friendly zero- conf library. But it does mean that for practical purposes, that's usually not what you want. Jean-Paul
![](https://secure.gravatar.com/avatar/b2240245799c094c7d834c4dc2cf2b48.jpg?s=120&d=mm&r=g)
Jean-Paul Calderone napisał(a):
I do not want to run my own mDNS service, I just want to advertize (publish) my webservice in running instance of mDNS. I think it would be Avahi mDNS/SD in most cases, but I cann't be sure now. The PyZeroconf library has many global state objects so I think it's not well suited for any forking environment. Python-avahi looks far better, but it requires gobject-based main loop to be used asynchronously (other way it can not connect to DBus signals). Itamar's module (mentioned by Thomas) seems to be perfect fit my needs if only I'd be able to implement service publishing part (discovery and browsing works well, after adapting the code to Twisted 2.5 layout). ;) -- Jarek Zgoda Skype: jzgoda | GTalk: zgoda@jabber.aster.pl | voice: +48228430101 "We read Knuth so you don't have to." (Tim Peters)
![](https://secure.gravatar.com/avatar/42148ea9c50179d54c77987a998af7a0.jpg?s=120&d=mm&r=g)
A while back I implemented a wrapper around pyzeroconf that integrated it into the twisted event loop. While we never did anything with this, it seemed to work fine. The design is not wonderful, but it does show how everything can be done. Here it is: http://projects.scipy.org/ipython/ipython/browser/ipython/sandbox/bgranger/b... At some point we might end up using this - let us know if it is helpful or worth putting somewhere more public. Brian On Dec 26, 2007 5:31 AM, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
![](https://secure.gravatar.com/avatar/769326b856fc9c7ef80a425fecd05ac9.jpg?s=120&d=mm&r=g)
On 12/26/07, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
we just used the Apple Rendezous code, it has a python wrapper around its C code. it is available for free from Apple's developer website. We had it in production for 2 years without a single hicup or restart.
![](https://secure.gravatar.com/avatar/3420ca67c72ac7c6674a4a980c3087d3.jpg?s=120&d=mm&r=g)
I've recently run into this issue as well Jarek. The easiest solution I found was to just launch a background 'avahi-publish' subprocess with the appropriate arguments. Send it a friendly kill signal when you wish to stop publishing and that's the end of it. It's a linux-specific solution, of course, but it's dirt simple and avoids the problem of multiple-mdns stacks on a single machine. If you'd like to support other platforms and/or non-avahi mdns stacks, it should be fairly straight-forward to write a small C/Python application for each that does the effectively the same thing. Likewise, for browsing services, I've decided to go the route of using 'avahi-browse' to extract the information for me rather than try and re-implement it directly in Python. Python is so damn friendly, I often forget that good ol' shell commands can often be the best tool for the job ;-) Cheers, Tom On Dec 26, 2007 7:31 AM, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
participants (8)
-
Bastian Winkler
-
Brian Granger
-
Jarek Zgoda
-
Jarrod Roberson
-
Jean-Paul Calderone
-
Phil Mayers
-
Thomas Hervé
-
Tom Cocagne