Re: Having trouble handling events

Irmen de Jong <[email protected]> Mon, 03 Mar 2014 21:36:00 +0100
Newsgroups gmane.comp.python.pyro
Message-ID <[email protected]>
On 3-3-2014 17:41, Tom Hanson wrote:
> Hey everyone!

Hi Tom!


> I'm trying to add Pyro4 events to my gobject MainLoop, but I'm having trouble with
> handling them.
> 
> This is some of some code that I've tried:
> 
> def start_pyro(self,device_id):
>     """Sets up Pyro, sharing Slave, and starting the eventloop"""
>     def handle_pyro(self, socket,*args):
>       daemon.events(socket)
>       return True
>       
>     slave = Slave()
>     
>     daemon=Pyro4.Daemon()
>     ns=Pyro4.locateNS()
>     uri=daemon.register(slave)
>     ns.register("pisync.slave.%s" % device_id, uri)
>     
>     gobject.io_add_watch(daemon.sockets[0],gobject.IO_IN,handle_pyro)
>     gobject.MainLoop().run()

I don't know what this does exactly (no experience with gobject/glib)

> 
> It seems to run fine, but when I try to access the object remotely the remote device
> just hangs and the local device displays:
> 
> Traceback (most recent call last):
>   File "modules/pyro_slave_new.py", line 83, in handle_pyro
>     print daemon.events([socket])


Hmm, you haven't shared this pyro_slave_new.py code with us, the code you pasted above
is from another module? Please provide the code that causes the crash.

I don't know what socket is in this context.


>   File "/usr/local/lib/python2.7/dist-packages/Pyro4/core.py", line 658, in events
>     return self.transportServer.events(eventsockets)
>   File "/usr/local/lib/python2.7/dist-packages/Pyro4/socketserver/threadpoolserver.py",
> line 133, in events
>     assert self.sock in eventsockets
> AssertionError
> 
> Could anyone point me to where I'm going wrong?


The assert is there to make sure you invoke the events method on a set of sockets that
at least contains the server socket from the daemon itself. The events method can and
does only react to data on that socket. Apparently you invoke it with a -list of-
sockets that does not contain the daemon's server socket, i.e. that 'socket' object from
line 83 is not the daemon's server socket.

Have a look at the 'eventloop' example that comes with Pyro, maybe it provides some
pointers?


By the way, what Pyro and Python versions are you using?

Cheers
Irmen de Jong



------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk