Turn the fan on 10 scs long python












0















This is my code turning the fan on i run the sleep on separate thread because it makes the entire script sleep



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()

def sleep_fan():
time.sleep(10)


The script is running however im not getting 10 scs it is only 1 or 2 seconds? How to fix this? TIA










share|improve this question























  • Should be daemon not deamon

    – smac89
    Nov 25 '18 at 7:29
















0















This is my code turning the fan on i run the sleep on separate thread because it makes the entire script sleep



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()

def sleep_fan():
time.sleep(10)


The script is running however im not getting 10 scs it is only 1 or 2 seconds? How to fix this? TIA










share|improve this question























  • Should be daemon not deamon

    – smac89
    Nov 25 '18 at 7:29














0












0








0








This is my code turning the fan on i run the sleep on separate thread because it makes the entire script sleep



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()

def sleep_fan():
time.sleep(10)


The script is running however im not getting 10 scs it is only 1 or 2 seconds? How to fix this? TIA










share|improve this question














This is my code turning the fan on i run the sleep on separate thread because it makes the entire script sleep



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()

def sleep_fan():
time.sleep(10)


The script is running however im not getting 10 scs it is only 1 or 2 seconds? How to fix this? TIA







python python-3.x python-2.7 gpio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 7:20









BeginnerBeginner

262210




262210













  • Should be daemon not deamon

    – smac89
    Nov 25 '18 at 7:29



















  • Should be daemon not deamon

    – smac89
    Nov 25 '18 at 7:29

















Should be daemon not deamon

– smac89
Nov 25 '18 at 7:29





Should be daemon not deamon

– smac89
Nov 25 '18 at 7:29












2 Answers
2






active

oldest

votes


















1














I'm going to assume that your program dies before the 10 seconds are up, which is what kills the fan. The misspelling of daemon in t.deamon = True doesn't matter here.



Probably better to join on that thread in your main function.



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()
return t

fan_thread = fan_on()
fan_thread.join() # waits for thread to exit before moving on.





share|improve this answer
























  • Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

    – Beginner
    Nov 27 '18 at 8:10











  • @Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

    – Adam Smith
    Nov 27 '18 at 16:52











  • sir how can I make not the entire script to sleep? after using the join?

    – Beginner
    Dec 2 '18 at 8:38



















-1














As Adam Smith said, the problem is because of your new thread dying almost instantly after creation and not because of daemon. Hence, you should use the join method.






share|improve this answer


























  • Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

    – Adam Smith
    Nov 25 '18 at 9:00











  • additionally this has nothing to do with the problem in this code.

    – Adam Smith
    Nov 25 '18 at 9:04











  • Oh, my bad. Thanks for the reply. Will edit the answer.

    – Vitrioil
    Nov 25 '18 at 9:29











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465469%2fturn-the-fan-on-10-scs-long-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I'm going to assume that your program dies before the 10 seconds are up, which is what kills the fan. The misspelling of daemon in t.deamon = True doesn't matter here.



Probably better to join on that thread in your main function.



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()
return t

fan_thread = fan_on()
fan_thread.join() # waits for thread to exit before moving on.





share|improve this answer
























  • Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

    – Beginner
    Nov 27 '18 at 8:10











  • @Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

    – Adam Smith
    Nov 27 '18 at 16:52











  • sir how can I make not the entire script to sleep? after using the join?

    – Beginner
    Dec 2 '18 at 8:38
















1














I'm going to assume that your program dies before the 10 seconds are up, which is what kills the fan. The misspelling of daemon in t.deamon = True doesn't matter here.



Probably better to join on that thread in your main function.



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()
return t

fan_thread = fan_on()
fan_thread.join() # waits for thread to exit before moving on.





share|improve this answer
























  • Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

    – Beginner
    Nov 27 '18 at 8:10











  • @Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

    – Adam Smith
    Nov 27 '18 at 16:52











  • sir how can I make not the entire script to sleep? after using the join?

    – Beginner
    Dec 2 '18 at 8:38














1












1








1







I'm going to assume that your program dies before the 10 seconds are up, which is what kills the fan. The misspelling of daemon in t.deamon = True doesn't matter here.



Probably better to join on that thread in your main function.



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()
return t

fan_thread = fan_on()
fan_thread.join() # waits for thread to exit before moving on.





share|improve this answer













I'm going to assume that your program dies before the 10 seconds are up, which is what kills the fan. The misspelling of daemon in t.deamon = True doesn't matter here.



Probably better to join on that thread in your main function.



def fan_on():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 23
GPIO.setup(FAN_PIN,GPIO.OUT)
GPIO.output(FAN_PIN,True)
t = Thread(target=sleep_fan)
t.deamon = True
t.start()
return t

fan_thread = fan_on()
fan_thread.join() # waits for thread to exit before moving on.






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 9:03









Adam SmithAdam Smith

33.6k53274




33.6k53274













  • Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

    – Beginner
    Nov 27 '18 at 8:10











  • @Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

    – Adam Smith
    Nov 27 '18 at 16:52











  • sir how can I make not the entire script to sleep? after using the join?

    – Beginner
    Dec 2 '18 at 8:38



















  • Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

    – Beginner
    Nov 27 '18 at 8:10











  • @Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

    – Adam Smith
    Nov 27 '18 at 16:52











  • sir how can I make not the entire script to sleep? after using the join?

    – Beginner
    Dec 2 '18 at 8:38

















Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

– Beginner
Nov 27 '18 at 8:10





Sir i have use the join and it is sucvessfully ran the fan by 10 scs however does this join affects the entire code? Because the sleep make the entire script to sleep after i used the join

– Beginner
Nov 27 '18 at 8:10













@Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

– Adam Smith
Nov 27 '18 at 16:52





@Beginner yes it does, but since your current problem is that the program dies before 10 seconds is up, that shouldn't be an issue, just make sure that your last instruction is to join on your fan thread.

– Adam Smith
Nov 27 '18 at 16:52













sir how can I make not the entire script to sleep? after using the join?

– Beginner
Dec 2 '18 at 8:38





sir how can I make not the entire script to sleep? after using the join?

– Beginner
Dec 2 '18 at 8:38













-1














As Adam Smith said, the problem is because of your new thread dying almost instantly after creation and not because of daemon. Hence, you should use the join method.






share|improve this answer


























  • Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

    – Adam Smith
    Nov 25 '18 at 9:00











  • additionally this has nothing to do with the problem in this code.

    – Adam Smith
    Nov 25 '18 at 9:04











  • Oh, my bad. Thanks for the reply. Will edit the answer.

    – Vitrioil
    Nov 25 '18 at 9:29
















-1














As Adam Smith said, the problem is because of your new thread dying almost instantly after creation and not because of daemon. Hence, you should use the join method.






share|improve this answer


























  • Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

    – Adam Smith
    Nov 25 '18 at 9:00











  • additionally this has nothing to do with the problem in this code.

    – Adam Smith
    Nov 25 '18 at 9:04











  • Oh, my bad. Thanks for the reply. Will edit the answer.

    – Vitrioil
    Nov 25 '18 at 9:29














-1












-1








-1







As Adam Smith said, the problem is because of your new thread dying almost instantly after creation and not because of daemon. Hence, you should use the join method.






share|improve this answer















As Adam Smith said, the problem is because of your new thread dying almost instantly after creation and not because of daemon. Hence, you should use the join method.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 9:42

























answered Nov 25 '18 at 8:53









VitrioilVitrioil

895




895













  • Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

    – Adam Smith
    Nov 25 '18 at 9:00











  • additionally this has nothing to do with the problem in this code.

    – Adam Smith
    Nov 25 '18 at 9:04











  • Oh, my bad. Thanks for the reply. Will edit the answer.

    – Vitrioil
    Nov 25 '18 at 9:29



















  • Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

    – Adam Smith
    Nov 25 '18 at 9:00











  • additionally this has nothing to do with the problem in this code.

    – Adam Smith
    Nov 25 '18 at 9:04











  • Oh, my bad. Thanks for the reply. Will edit the answer.

    – Vitrioil
    Nov 25 '18 at 9:29

















Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

– Adam Smith
Nov 25 '18 at 9:00





Strongly disagree. setDaemon is a silly name for a silly method, and even the documentation includes this line: "Old getter/setter API for daemon; use it directly as a property instead."

– Adam Smith
Nov 25 '18 at 9:00













additionally this has nothing to do with the problem in this code.

– Adam Smith
Nov 25 '18 at 9:04





additionally this has nothing to do with the problem in this code.

– Adam Smith
Nov 25 '18 at 9:04













Oh, my bad. Thanks for the reply. Will edit the answer.

– Vitrioil
Nov 25 '18 at 9:29





Oh, my bad. Thanks for the reply. Will edit the answer.

– Vitrioil
Nov 25 '18 at 9:29


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465469%2fturn-the-fan-on-10-scs-long-python%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)