On Thu, Feb 28, 2013 at 04:13:36PM +0800, can. wrote:
> Hi there,
> 
> I'm trying to figure out ryu's event mechanism by sending and receiving an
> event. Below is the test code I wrote:
> ---------
> from ryu.base import app_manager
> from ryu.controller import event, handler
> 
> class Hehe(app_manager.RyuApp):
> 
>     class Event_1(event.EventBase):
>         def __init__(self):
> super(Hehe.Event_1, self).__init__()
>             self.msg = 'event 1'
> 
>     def __init__(self):
>         super(Hehe, self).__init__()
>         self.event = Hehe.Event_1()
>         self.register_observer(Hehe.Event_1, self.name)
> 
>     def ping(self):
>         self.send_event_to_observers(self.Event_1())
>         print 'pinging...'
> 
>     @handler.set_ev_cls(Hehe.Event_1)
>     def pong(self, event):
>         print 'Got ya', event.msg
> ---------
> I put the script in ryu/app, and ran it with "ryu-manager event.py".
> But I got a NameError stating that "name 'Hehe' is not defined" in line
> "@handler.set_ev_cls(Hehe.Event_1)". 
> What do I miss? I need some help about this minimal example of raising and
> handling an event(especially a self-defined event).
> Thank you in advance.

When calling the decorator, @handler.set_ev_cls(Hehe.Event_1),
the class Hehe isn't defined yet.  It's being defined.
the definition isn't finished yet So the referncing Hehe.Event_1 fails.

Moving out Event_1 out of class Hehe would work, I guess.

Class Event_1(event.EventBase):
    ...

class Hehe(...):
    ...
    @handler.set_ev_class(Event_1)
    def pong(...)


thanks,



> 
> --
> Best regards, 
> Can Zhang

> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel


-- 
yamahata

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to