<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Yea, Ctrl+D works but exit() does not. Sorry I did not test Ctrl+D<br>
    <div class="moz-cite-prefix">On 9/6/2012 8:03 PM, Murphy McCauley
      wrote:<br>
    </div>
    <blockquote
      cite="mid:5B0093F2-776C-4DA8-9986-EB47E9FD0F05@gmail.com"
      type="cite">
      <div>I'm using the MurphyMc/pox fork, which may or may not make a
        difference.  It works fine if you quit using Ctrl-D at the
        interpreter or by Ctrl-C without the interpreter...</div>
      <div><br>
      </div>
      <div>$ cat ext/zzz.py</div>
      <div>import pox.core</div>
      <div><br>
      </div>
      <div>def handler (event):</div>
      <div>  print "EVENT", type(event)</div>
      <div><br>
      </div>
      <div>pox.core.core.addListener(pox.core.GoingUpEvent, handler)</div>
      <div>pox.core.core.addListener(pox.core.GoingDownEvent, handler)</div>
      <div>$</div>
      <div><br>
      </div>
      <div>$ ./pox.py zzz</div>
      <div>POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.</div>
      <div>EVENT <class 'pox.core.GoingUpEvent'></div>
      <div>INFO:core:POX 0.0.0 is up.</div>
      <div>This program comes with ABSOLUTELY NO WARRANTY.  This program
        is free software,</div>
      <div>and you are welcome to redistribute it under certain
        conditions.</div>
      <div>Type 'help(pox.license)' for details.</div>
      <div>Ready.</div>
      <div>POX> ^D</div>
      <div>INFO:core:Going down...</div>
      <div>EVENT <class 'pox.core.GoingDownEvent'></div>
      <div>INFO:core:Down.</div>
      <div>$</div>
      <div><br>
      </div>
      <div>
        <div>$ ./pox.py --no-cli zzz</div>
        <div>POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.</div>
        <div>EVENT <class 'pox.core.GoingUpEvent'></div>
        <div>INFO:core:POX 0.0.0 is up.</div>
        <div>^CINFO:core:Going down...</div>
        <div>EVENT <class 'pox.core.GoingDownEvent'></div>
        <div>INFO:core:Down.</div>
      </div>
      <div>$</div>
      <div><br>
      </div>
      <div>
        <div>It doesn't work like that if you quit using exit(). </div>
      </div>
      <div><br>
      </div>
      <div>$ ./pox.py zzz</div>
      <div>
        <div>POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.</div>
        <div>EVENT <class 'pox.core.GoingUpEvent'></div>
        <div>INFO:core:POX 0.0.0 is up.</div>
        <div>This program comes with ABSOLUTELY NO WARRANTY.  This
          program is free software,</div>
        <div>and you are welcome to redistribute it under certain
          conditions.</div>
        <div>Type 'help(pox.license)' for details.</div>
        <div>Ready.</div>
        <div>POX> exit()</div>
      </div>
      <div>$</div>
      <div><br>
      </div>
      <div>I've pushed a change to MurphyMc/pox so that exit() from the
        interpreter works as expected, but sys.exit() still exits
        immediately (I am hesitant to use atexit to change the latter).</div>
      <div><br>
      </div>
      <div>For your case, though, you might just want to check
        core.running -- it's a flag which changes to False when POX is
        going down.</div>
      <div><br>
      </div>
      <div>-- Murphy</div>
      <div><br>
      </div>
      <div>
        <div>On Sep 6, 2012, at 7:23 PM, Masoud Moshref Javadi wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">
          <meta content="text/html; charset=ISO-8859-1"
            http-equiv="Content-Type">
          <div bgcolor="#FFFFFF" text="#000000"> This is my code:<br>
            ThreadRule is a thread that creates opens a socket. and
            checks the flag if the flag is false it will stop<br>
            <br>
            The GoingUpEvent works but the GoingDownEvent does not. So
            is it even the right way to do cleanup for a pox controller?<br>
            <br>
            class my_l2_learning (EventMixin):<br>
              def __init__ (self, port):<br>
                self.listenTo(core.openflow)<br>
            <br>
                self.t = ThreadRule(port)<br>
                self.t.start()<br>
                #core.addListener(pox.core.GoingUpEvent,
            self._handle_GoingUpEvent)<br>
                 core.addListener(pox.core.GoingDownEvent,
            self._handle_GoingDownEvent)<br>
            <br>
              def _handle_GoingDownEvent (self, event):<br>
                    self.t.flag=False<br>
                    print('go down')<br>
             def _handle_GoingUpEvent (self, event):<br>
                    print ("go up")<br>
            <br>
            <br>
            <br>
            <div class="moz-cite-prefix">On 9/6/2012 3:04 PM, Murphy
              McCauley wrote:<br>
            </div>
            <blockquote
cite="mid:CAHC=y9QscxBK2d07dW_TU3vdZwTzjfPKE02W+R=UvdeiArLdKw@mail.gmail.com"
              type="cite">
              <p>Can you post the code that you tried?</p>
              <p>-- Murphy</p>
              <div class="gmail_quote">On Sep 6, 2012 2:29 PM, "Masoud
                Moshref Javadi" <<a moz-do-not-send="true"
                  href="mailto:moshrefj@usc.edu">moshrefj@usc.edu</a>>
                wrote:<br type="attribution">
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex"> I
                  want to run a method when the controller goes down to
                  close a socket.<br>
                  I tried to register for pox.core.GoingDownEvent but it
                  does not work. Is there any special way to be informed
                  on the exit of pox?<br>
                  <br>
                  -- <br>
                  Masoud Moshref Javadi<br>
                  Computer Engineering PhD Student<br>
                  Ming Hsieh Department of Electrical Engineering<br>
                  University of Southern California<br>
                  <br>
                </blockquote>
              </div>
            </blockquote>
            <br>
            <pre class="moz-signature" cols="72">-- 
Masoud Moshref Javadi
Computer Engineering PhD Student
Ming Hsieh Department of Electrical Engineering
University of Southern California</pre>
          </div>
        </blockquote>
      </div>
      <br>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Masoud Moshref Javadi
Computer Engineering PhD Student
Ming Hsieh Department of Electrical Engineering
University of Southern California</pre>
  </body>
</html>