Sole_Wolf, on 04 August 2012 - 02:34 PM, said:
A friend and I are disagreeing on how a python script should run.
He wants the script to run once a second in an infinite loop while I want the script to run once a minute via cron daemon and not in an infinite loop.
His reason being, he wants for the data that is sent to the server to be in real-time.
How much would performance be impacted if the script is in an infinite loop that uploads data to a server?
I'm not entirely sure that this is really a question of 'practice' in that both of the methods are okay at certain things. It would therefore be good practice to just choose the solution which is most suited to you.
Obviously we can't advise well given the lack of information you've given us. Does the data have to be sent in 'real-time'? In general, it won't anyway because web requests take time.
Performance wise, cron is probably better. When using the loop approach as long as you make the thread sleep for a while after every iteration it should be fine (otherwise it won't relinquish the cpu and you'll max out one of your cores).
Another thing to consider is what happens if the infinite loop approach crashes. Where with cron it'd just get run again the next minute (and assuming that doesn't crash again, you only lose a minutes data) with an infinite loop you'd have to have some way of restarting the script.
If you give us more information, we'll be able to be a bit more helpful.