Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Python (http://www.chiefdelphi.com/forums/forumdisplay.php?f=187)
-   -   Not restarting (http://www.chiefdelphi.com/forums/showthread.php?t=102714)

tux 13-02-2012 15:41

Not restarting
 
I got the netconsole working, so I can now see the output while the code is running.

I am using the "simple" example as a starting point, but the restart functionality is not working properly. When I hit the button for restart, I see the exception output on the netconsole, but the code is not restarted, it acts like it is just hung up.

Is there something special I need to do to make the code restart once an exception is raised?

virtuald 13-02-2012 23:51

Re: Not restarting
 
The example is outdated, the boot.py no longer reloads the code when an uncaught exception occurs. You can type 'reboot' at the NetConsole to reset the robot.

tux 14-02-2012 11:40

Re: Not restarting
 
Ah. Ok. Now that I re-read the 2012.1 announcement I see the note about restarting.

So, if I change the RuntimeError exception to SystemRestart, then the interpreter should be restarted -- or at least it should try to. There may be other issues around that, but for testing it may be usable.

tux 14-02-2012 12:36

Re: Not restarting
 
Quote:

Originally Posted by virtuald (Post 1126183)
You can type 'reboot' at the NetConsole to reset the robot.

Is that the same as pressing the reset button on the cRio or is it faster?

tkbletsc 16-01-2013 23:45

Re: Not restarting
 
I haven't had a chance to test this on the robot, but given the warnings around the SystemRestart exception ("This is still not all that reliable..."), I wonder if using Python's own reload() would be better?

This works on my local machine...any reason not to do something like this? Also, anyone have an idea how to improve it?

robot.py:
Code:

from my_exceptions import RestartException
import real_code

while True:
        try:
                reload(real_code)
                real_code.go()
        except RestartException:
                print "Reloading and restarting..."
                pass

my_exceptions.py:
Code:

class RestartException(Exception): pass
real_code.py:
Code:

from my_exceptions import RestartException

import sys,os,re,time

# decide if we need to reload based on some signal, in this case a file existing
which we delete
# on the robot, this would be a joystick check
def check_restart():
        if os.path.exists("do_reload"):
                os.unlink("do_reload")
                raise RestartException

def go():
        while True:
                check_restart()
                print "Test."
                time.sleep(1)

With the above, if I have it running in one window, edit real_code.py, then create "do_reload", the real_code.py is reloaded and restarted at the next tick.


All times are GMT -5. The time now is 19:52.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi