1

I'm running the following python code:

import os

day='09'
month='08'
year='2016'
hours='14'
minutes='30'
seconds='00'
dt="sudo date -s '" + day + " " + month + " " + year + " " + hours + ":" + minutes + ":" + seconds + "'"
os.system(dt)

when I run this script, it always work true and set my raspberry pi date and time correctly, but the problem is that it takes very very long time to execute most of the time. if I write a simple print command after calling os.system(dt), it cost me more than 10 seconds to see the print command output and some times it cost less than a second (but this happens rarely).

Knowing that all my tries are done with same parameters, and some of these tries executed in less than a second and most of them executed in more than 10 seconds. This means that the problem is not with a wrong date/Time parameter value.

Any suggestions will be so appreciated

Note: I tried to run another script that prints some text every 1 second, and then I ran the above script when it reached os.system(dt), the second seperated script freezed as well as the above one. which means that the problem is that my whole pi is frozen when calling this command. does anyone know what's happening! How could such a simple command froze my whole pi!!

Dani
  • 469
  • 1
  • 6
  • 17
  • Is that the complete script? How are you invoking the script? – joan Aug 12 '16 at 07:51
  • I'm using it as a test script, and when I get it worked I'll implement it with an organized function. – Dani Aug 12 '16 at 08:00
  • How are you running the script? What command do you type? – joan Aug 12 '16 at 08:01
  • from idle>> Run >>Run Module – Dani Aug 12 '16 at 08:04
  • As it stands the script is illegal. You need import os at the start. It runs fine for me then. – joan Aug 12 '16 at 08:06
  • sorry for not typing it, I already importing os (for sure I'm doing as I told you it works correctly, it's just taking long time) please read my new update on the question, I noticed that my whole pi is frozen. – Dani Aug 12 '16 at 08:12
  • 2
    I suggest you don't use IDLE. Just enter the script in a file called anything, e.g. x.py, make the file executable, e.g. chmod +x x.py, and run it from the command line, e.g. ./x.py. Take note of any errors and correct. – joan Aug 12 '16 at 08:19
  • @joan I've just seen your comment here. I will consider this as it applies to my recent question Why would os.system('sudo pigpiod') fail silently, but only part of the time? as well. Do you think that os.system("command") in a running Python script (IDLE or otherwise) is in any way problematic, or is this just something handy to know how to do? – uhoh Mar 14 '18 at 08:27

0 Answers0