Go to Post I think he GDC is just rick-rolling all of us. - z_beeblebrox [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-01-2013, 23:45
tkbletsc tkbletsc is offline
Registered User
FRC #4561
 
Join Date: Jan 2013
Location: Raleigh, NC
Posts: 10
tkbletsc is just really nicetkbletsc is just really nicetkbletsc is just really nicetkbletsc is just really nice
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:40.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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