Re: Having trouble handling events
Tom Hanson <[email protected]> Mon, 3 Mar 2014 22:28:53 +0000
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <CAAv+Oaa9AVTDcV=_ZgCbgGYxfAfcsPSUt1nONrFrWWG6gwUx=w@mail.gmail.com> |
I do have to apologise, I even looked through the source code to see what
was going on, but failed to notice that there were examples!
This is the working code that I have used based on the gui_nothreads.py
example:
def install_pyro_event_callback(daemon):
"""
Add a callback to the tkinter event loop that is invoked every so often.
The callback checks the Pyro sockets for activity and dispatches to the
daemon's event process method if needed.
"""
def pyro_event():
while True:
s,_,_ = select.select(daemon.sockets,[],[],0.01)
if s:
daemon.events(s)
else:
break
gobject.timeout_add(20, pyro_event)
return True
gobject.timeout_add(20, pyro_event)
Previously, I was attempting to act on an event triggered by the sockets in
use!
Thanks!
Tom Hanson
On Mon, Mar 3, 2014 at 8:36 PM, Irmen de Jong <[email protected]> wrote:
> 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
> _______________________________________________
> Pyro-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyro-core
>
------------------------------------------------------------------------------
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
_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core