|
From: Gibhardt, H. <hg...@gw...> - 2011-11-21 10:44:37
|
Dear Michael,
thank you for your reply. Here are my comments:
>What do you mean by hangs up?
The python control program hangs: no input possible, no Ctrl-C; even after
minutes. I have to shot up my python program.
>How does this make file access "unsafe"? (I don't know what you mean by
unsafe here?)
I mean, the write-routine does not check, if the file handler to the file is
valid. In that sense here, it might be that the file is blocked and you do
not get an error from configobj, although you cannot open it and write to it.
>Can you show me the actual code? Do you just catch and ignore exceptions
raised during writing? That sounds like a bad idea in general.
My code is now:
from configobj import ConfigObj
from time import *
from errlog import *
class GammaConfigObj(ConfigObj):
def __init__(self, infile=None, options=None, **kwargs):
ConfigObj.__init__(self,infile,options,**kwargs)
def writeconfig(self,Attempts=2):
for att in range(Attempts):
try:
self.write()
break
except:
if (att +1 < Attempts):
mess = 'Writing to gamma.ini failed - Trying again.'
print mess
logerror('config',mess)
sleep(3)
else:
mess = 'Writing to gamma.ini failed - Stop and Raise
Error'
logerror('config',mess)
raise GammaError(mess)
Now, the problem of robocopy and configobj is catched by attempting several
times the writing with a small waiting time and the program can continue if
it was successful. The occurrence of the error is logged. And if after the
number of attempts the writing is not possible, the program aborts with an
error. Since we added this functionality, we have a list with the occurrences
of the error and comes roughly every 2 days.
Best regards
Holger
|