How to make a python script reboot itself
I work actually on my raspberry 3 without internet for my internship.
Firstly I created a python script that I schedule with Cron to update my raspberry's hour every 12h.
Secondly, I have another script should run continually.
But I observed that, when I update the time, my script that run continually, doesn't update its datetime.
So I would like to reboot it, to allow the script to take the time in consideration.
here my script I would like to reboot.
from math import *
import pyorbital
from pyorbital import tlefile
from pyorbital.orbital import Orbital
import serial
import time
from datetime import datetime
import os
import sat_class
import predict
import rotator_treshold_test
def rotator_set (azel,v):
if v == False:
az = 0
el = 90
print(('waiting n azimuth = %f elevation = %fnn')%(az,el))
else:
az = azel[0]
if azel[1] < 0:
el = 0
else :
el = azel[1]
print(('tracking satellite n azimuth = %f elevation = %fnn')%(az,el))
def satellite_track():
k=0
saved = [0]
p = '?'
b = '?'
sat = sat_class.Satellite()
mission = predict.Mission()
verif = mission.verif
if verif == False:
mission = predict.Mission()
now= mission.now
print(now)
azel = [0,0] # we don't need to put azel here we are in waiting mode .
rotator_set(azel,verif)
time.sleep(29)
else :
mission= predict.Mission()
print("current time1: ",mission.now,'n',mission.start,' ',mission.end)
verif1 = mission.verif
end = mission.end
now2 = mission.now
while now2 <= end :
azel = rotator_treshold_test.az_correct(saved[k])
rotator_set(azel,verif1)
saved.append(rotator_treshold_test.az_correct(azel[0]))
k+=1
mission = predict.Mission()
now2 = mission.now
print(now2)
time.sleep(0.8)
##I would like to reboot my script here
while True :
satellite_track()
raspberry-pi3
add a comment |
I work actually on my raspberry 3 without internet for my internship.
Firstly I created a python script that I schedule with Cron to update my raspberry's hour every 12h.
Secondly, I have another script should run continually.
But I observed that, when I update the time, my script that run continually, doesn't update its datetime.
So I would like to reboot it, to allow the script to take the time in consideration.
here my script I would like to reboot.
from math import *
import pyorbital
from pyorbital import tlefile
from pyorbital.orbital import Orbital
import serial
import time
from datetime import datetime
import os
import sat_class
import predict
import rotator_treshold_test
def rotator_set (azel,v):
if v == False:
az = 0
el = 90
print(('waiting n azimuth = %f elevation = %fnn')%(az,el))
else:
az = azel[0]
if azel[1] < 0:
el = 0
else :
el = azel[1]
print(('tracking satellite n azimuth = %f elevation = %fnn')%(az,el))
def satellite_track():
k=0
saved = [0]
p = '?'
b = '?'
sat = sat_class.Satellite()
mission = predict.Mission()
verif = mission.verif
if verif == False:
mission = predict.Mission()
now= mission.now
print(now)
azel = [0,0] # we don't need to put azel here we are in waiting mode .
rotator_set(azel,verif)
time.sleep(29)
else :
mission= predict.Mission()
print("current time1: ",mission.now,'n',mission.start,' ',mission.end)
verif1 = mission.verif
end = mission.end
now2 = mission.now
while now2 <= end :
azel = rotator_treshold_test.az_correct(saved[k])
rotator_set(azel,verif1)
saved.append(rotator_treshold_test.az_correct(azel[0]))
k+=1
mission = predict.Mission()
now2 = mission.now
print(now2)
time.sleep(0.8)
##I would like to reboot my script here
while True :
satellite_track()
raspberry-pi3
add a comment |
I work actually on my raspberry 3 without internet for my internship.
Firstly I created a python script that I schedule with Cron to update my raspberry's hour every 12h.
Secondly, I have another script should run continually.
But I observed that, when I update the time, my script that run continually, doesn't update its datetime.
So I would like to reboot it, to allow the script to take the time in consideration.
here my script I would like to reboot.
from math import *
import pyorbital
from pyorbital import tlefile
from pyorbital.orbital import Orbital
import serial
import time
from datetime import datetime
import os
import sat_class
import predict
import rotator_treshold_test
def rotator_set (azel,v):
if v == False:
az = 0
el = 90
print(('waiting n azimuth = %f elevation = %fnn')%(az,el))
else:
az = azel[0]
if azel[1] < 0:
el = 0
else :
el = azel[1]
print(('tracking satellite n azimuth = %f elevation = %fnn')%(az,el))
def satellite_track():
k=0
saved = [0]
p = '?'
b = '?'
sat = sat_class.Satellite()
mission = predict.Mission()
verif = mission.verif
if verif == False:
mission = predict.Mission()
now= mission.now
print(now)
azel = [0,0] # we don't need to put azel here we are in waiting mode .
rotator_set(azel,verif)
time.sleep(29)
else :
mission= predict.Mission()
print("current time1: ",mission.now,'n',mission.start,' ',mission.end)
verif1 = mission.verif
end = mission.end
now2 = mission.now
while now2 <= end :
azel = rotator_treshold_test.az_correct(saved[k])
rotator_set(azel,verif1)
saved.append(rotator_treshold_test.az_correct(azel[0]))
k+=1
mission = predict.Mission()
now2 = mission.now
print(now2)
time.sleep(0.8)
##I would like to reboot my script here
while True :
satellite_track()
raspberry-pi3
I work actually on my raspberry 3 without internet for my internship.
Firstly I created a python script that I schedule with Cron to update my raspberry's hour every 12h.
Secondly, I have another script should run continually.
But I observed that, when I update the time, my script that run continually, doesn't update its datetime.
So I would like to reboot it, to allow the script to take the time in consideration.
here my script I would like to reboot.
from math import *
import pyorbital
from pyorbital import tlefile
from pyorbital.orbital import Orbital
import serial
import time
from datetime import datetime
import os
import sat_class
import predict
import rotator_treshold_test
def rotator_set (azel,v):
if v == False:
az = 0
el = 90
print(('waiting n azimuth = %f elevation = %fnn')%(az,el))
else:
az = azel[0]
if azel[1] < 0:
el = 0
else :
el = azel[1]
print(('tracking satellite n azimuth = %f elevation = %fnn')%(az,el))
def satellite_track():
k=0
saved = [0]
p = '?'
b = '?'
sat = sat_class.Satellite()
mission = predict.Mission()
verif = mission.verif
if verif == False:
mission = predict.Mission()
now= mission.now
print(now)
azel = [0,0] # we don't need to put azel here we are in waiting mode .
rotator_set(azel,verif)
time.sleep(29)
else :
mission= predict.Mission()
print("current time1: ",mission.now,'n',mission.start,' ',mission.end)
verif1 = mission.verif
end = mission.end
now2 = mission.now
while now2 <= end :
azel = rotator_treshold_test.az_correct(saved[k])
rotator_set(azel,verif1)
saved.append(rotator_treshold_test.az_correct(azel[0]))
k+=1
mission = predict.Mission()
now2 = mission.now
print(now2)
time.sleep(0.8)
##I would like to reboot my script here
while True :
satellite_track()
raspberry-pi3
raspberry-pi3
asked Nov 21 '18 at 15:55
intern00intern00
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could use os.execl()
to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415882%2fhow-to-make-a-python-script-reboot-itself%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use os.execl()
to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
add a comment |
You could use os.execl()
to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
add a comment |
You could use os.execl()
to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
You could use os.execl()
to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
answered Nov 21 '18 at 15:57
FMarazziFMarazzi
323213
323213
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
add a comment |
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
Ho ! Thanks you so much, that was so much easier that I thought .
– intern00
Nov 22 '18 at 14:05
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
No problem! Then please accept the answer and maybe upvote :)
– FMarazzi
Nov 22 '18 at 16:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
I don't understand, I tried it the first time on my raspberry, it worked. Now when I try it, I have this error message ( " execl() missing 1 required positional argument: 'file'" I tried to put " os.__file__" as an argument but it doesn't work. I have the same probleme with "os.execv(os.__file__,args) And I don't understand which arg to put for " agrs "
– intern00
Nov 26 '18 at 13:33
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
You have to provide the argument to the function, which is the python file you want to reboot (i.e. "./main.py")
– FMarazzi
Nov 26 '18 at 13:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415882%2fhow-to-make-a-python-script-reboot-itself%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown