|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Re: Not restarting
Is that the same as pressing the reset button on the cRio or is it faster?
|
|
#5
|
|||
|
|||
|
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 Code:
class RestartException(Exception): pass 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)
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|