I'm having an issue with my websocket script. Over time it consumes more and more CPU. One remedy I've discovered is to clear the associated logfile. This resolves the problem for a little while, but the CPU usuage builds up to 120% in little over a day or so. (using the top command on the linux server)
The part of the script that does the file write looks a bit odd to me. Here is the code:
f = open(file, 'a')
f.write(line+"\n")
os.fsync(f.fileno())
f.flush()
f.close
I'm not a Python expert, but for starters, the last three things do rather the same in my opinion. The python manual states http://docs.python.org/2/library/os.html#os.fsync that f.flush and os.fsync should be in reverse order...
Can I just use:
f = open(file, 'a')
f.write(line+"\n")
f.close
and should it not be: f.close()??
Any ideas?
f.close()close()implies aflush(), and I've no idea whatfsync()is meant to accomplish if you're already working on a file object and not on the raw handles.