Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvice on writing to a log file with python
    primarykey
    data
    text
    <p>I have some code that will need to write about 20 bytes of data every 10 seconds. I'm on Windows 7 using python 2.7</p> <p>You guys recommend any 'least strain to the os/hard drive' way to do this?</p> <p>I was thinking about opening and closing the same file very 10 seconds:</p> <pre><code>f = open('log_file.txt', 'w') f.write(information) f.close() </code></pre> <p>Or should I keep it open and just <code>flush()</code> the data and not close it as often?</p> <p>What about <code>sqllite</code>? Will it improve performance and be less intensive than the open and close file operations? (Isn't it just a flat file database so == to text file anyways...?)</p> <p>What about <code>mysql</code> (this uses a local server/process.. not sure the specifics on when/how it saves data to hdd) ?</p> <p>I'm just worried about not frying my hard drive and improving the performance on this logging procedure. I will be receiving new log information about every 10 seconds, and this will be going on 24/7 24 hours a day. Your advice?</p> <p>ie: Think about programs like utorrent that require saving large amounts of data on a constant basis for long periods of time, (my log file is significantly less data that those being written in such "downloader type programs" like utorrent)</p> <pre><code>import random import time def get_data(): letters = 'isn\'t the code obvious' data = '' for i in xrange(20): data += random.choice(letters) return data while True: f = open('log_file.txt', 'w') f.write(get_data()) f.close() time.sleep(10) </code></pre> <p>My CPU starts whining after about 15 seconds... (or is that my hdd? )</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload