<div dir="ltr"><div><div>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">That's why you should write an error log ;)</blockquote>
<div> </div>
The error log is a valid point. Is there a way to capture the error
messages that go the the terminal window or command prompt rather than
all my print statements? Can this be set up as a global thing for the
whole application rather than inside each thread?<br><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><div class="gmail_quote"><div>try:</div><div> put your function here</div>
<div>except:</div><div> print 'oops! an error occurred!'</div></div></div></blockquote><br>
I'll probably resort to this and have done in a couple of other
occasions, but thought it was generally frowned upon! I Guess I could
do that and print out anything caught by the exception into a log and
go more specific at a later date.<br>
<br>
Cheers,<br>
<br>
Wesley Brooks<br><br> </div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><div class="Ih2E3d">On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <span dir="ltr"><<a href="mailto:wesbrooks@gmail.com" target="_blank">wesbrooks@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Unfortunately due to the nature of the program the error
has normally happened hours ago and the error message has disappeared
from the buffer of the command prompt.</div></blockquote><div><br></div></div><div>That's why you should write an error log ;)</div><div class="Ih2E3d">
<div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><br>This is the function:<br><br>def CommandFileWriter(self, command):<br>
name1 = os.path.join(self.commandsdir, command + '.temp')<br>
name2 = os.path.join(self.commandsdir, command)<br> comfile = open(name1, 'w')<br>
comfile.close()<br> if not os.path.exists(name2):<br> os.rename(name1, name2)<br> else:<br> os.remove(name1)<br><br>This
was the best way I could come up with doing the function. So the file
is written to the correct directory with a wrong name (so the other
program will ignore it) then it's name is changed to the correct name
with os.rename. Unfortunately I think in freak occations the other
program can read and delete the file (running on a multicore processor
system) during the rename operation. Can you suggest which errors I
should be trying to catch?</div>
</blockquote><div><br></div></div><div>I'm not sure what errors to
catch, but it's always possible to use a general catchall (I'm not sure
if this is particularly pythonic)</div><div><br></div><div>try:</div><div> put your function here</div><div>except:</div><div> print 'oops! an error occurred!'</div><div><br></div><div>Or
do something besides print an error (such as write a message to a
logfile. If you include the time stamp and some other info that might
be helpful that may give you some more insight as to where the problem
is, and if it's something you can fix.)</div></blockquote>
</div></div>