[zeromq-dev] pyczmq: zloop callback arguments?

Michael Haberler mail17 at mah.priv.at
Wed Nov 20 22:35:12 CET 2013


Michel,

this closes the issue.

--

actually I had two issues in my code - I had already tried wrapping the self argument as ffi.new_handle(self) which caused the timer callback to be executed; however I got a 'From callback <function timer_event at 0xa7dbed4>:

Trying to convert the result back to C:
TypeError: an integer is required

well, the callback should return an int, not None. That's all, making all sense now.

thanks! 

- Michael

Am 20.11.2013 um 19:10 schrieb Michel Pelletier <pelletier.michel at gmail.com>:

> https://github.com/zeromq/pyczmq/pull/8
> 
> -Michel
> 
> 
> On Wed, Nov 20, 2013 at 8:14 AM, Michel Pelletier <pelletier.michel at gmail.com> wrote:
> Ah I see what's up, poller() automatically wraps the arg in new_handle, but timer does not.  In either case the callback author has to unbox the handle back into whatever it was they passed in.  I'll push a PR.
> 
> -Michel
> 
> 
> On Wed, Nov 20, 2013 at 8:07 AM, Michel Pelletier <pelletier.michel at gmail.com> wrote:
> Yes this is unfortunate, the arg can only be something fii thinks is a pointer.  You have to "box/unbox" it with ffi.new_handle/fii.from_handle
> 
> http://cffi.readthedocs.org/en/release-0.8/#misc-methods-on-ffi
> 
> -Michel
> 
> 
> On Wed, Nov 20, 2013 at 4:09 AM, Michael Haberler <mail17 at mah.priv.at> wrote:
> I'm stuck at passing 'self' as a timer callback argument:
> 
> Class Test:
> 
>     @ffi.callback('zloop_fn')
>     def timer_event(loop, item, arg):
>        print type(loop), type(item), type(arg)
> 
>     def __init__(self):
>         ...
>         zloop.timer(self.loop, msec, 1, self.timer_event, self)
>         # this raises: TypeError: initializer for ctype 'void *' must be a cdata pointer, not instance
> 
> how do I coerce this into action?
> 
> - Michael
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> 
> 
> 
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev




More information about the zeromq-dev mailing list