I'm running the following python code:

import os

dt="sudo date -s '" + day + " " + month + " " + year + " " + hours + ":" + minutes + ":" + seconds + "'"

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!!

  • Is that the complete script? How are you invoking the script?
    – joan
    Commented Aug 12, 2016 at 7:51
  • I'm using it as a test script, and when I get it worked I'll implement it with an organized function.
    – Dani
    Commented Aug 12, 2016 at 8:00
  • How are you running the script? What command do you type?
    – joan
    Commented Aug 12, 2016 at 8:01
  • from idle>> Run >>Run Module
    – Dani
    Commented Aug 12, 2016 at 8:04
  • 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
    Commented Aug 12, 2016 at 8:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.