I cant seem to get any response when attempting to run these two functions simultaneously












2















I am working on a final project for my python class and I have been desperately attempting to get these two processes to run at the same time, but when I run them I get no responses from either functions.



import threading, time
count = 0
clock = 1200 - count
def f1():

while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()

def f2():
pass

threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Apologies if this is a silly question, I just cant seem to get anything to work and I just want to be able to take reference from the timer in the first function from the second function during play.
Also to give some context, in the second function I am creating an escape room that will use the first function to check how much time they have left to escape.





Basically now I incorporated a section to the second part of my function to test and see if I could pull information from my first function to the second. This time both programs worked well simultaneously but due to my noob level knowledge when it comes to python, I wasn't sure how I would be able to get the updated version of count from my first function.



import threading, time
count = 0
def f1():
global count
while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()
return count


def f2():
clock = 1200 - count
p = 1
while True:
while p == 1:
if p == 1:
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
print("It seems you wont be able to get any clear information without inspecting each thing")
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
time.sleep(5)
desk = input("What do you do?")

if desk.lower() == ("inspect clock"):
print("You look up at the digital clock on the wall.")
print("Glowing red, the clock continues to count down.")
print("You seem to have", clock," seconds left")

elif desk.lower() == ("inspect box"):
print("After clear inspection of the box, you note that each of the buttons are a color of the rainbow")
print("However, you also notice that each button has a number written on it.")
print("The numbers and colors are as follows:")
print("'Red, 4 / Orange, 3 / Yellow, 6 / Green, 5 / Blue, 2 / Purple, 1")

elif desk.lower() == ("inspect paper"):
import Rainbow
print("Click the window to stop looking at the paper")

elif desk.lower() == ("get up"):
print("You find it impossible to move due to the chains wrapped around your legs.")
print("There is also a lock sitting on your lap, preventing you from removing the chain.")

elif desk.lower() == ("inspect lock"):
print("It is a lock, no key attached though")

elif desk.lower() ==("solve box"):
box = input("What is the solution? R=4,O=3,Y=6,G=5,B=2,P=1")
if box.lower() == ("43621"):
p = 2
else:
print("The box does nothing, mustve been the wrong combination")


else:
print("Invalid input. Retry.")



threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Basically I want to be able to use the input "inspect clock" and get the updated count from the timer function. This is probably a silly question, apologies if it is.










share|improve this question

























  • You have a local and a global version of the count variable.

    – Klaus D.
    Nov 22 '18 at 4:00











  • Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

    – Nick Offenberger
    Nov 22 '18 at 4:03
















2















I am working on a final project for my python class and I have been desperately attempting to get these two processes to run at the same time, but when I run them I get no responses from either functions.



import threading, time
count = 0
clock = 1200 - count
def f1():

while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()

def f2():
pass

threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Apologies if this is a silly question, I just cant seem to get anything to work and I just want to be able to take reference from the timer in the first function from the second function during play.
Also to give some context, in the second function I am creating an escape room that will use the first function to check how much time they have left to escape.





Basically now I incorporated a section to the second part of my function to test and see if I could pull information from my first function to the second. This time both programs worked well simultaneously but due to my noob level knowledge when it comes to python, I wasn't sure how I would be able to get the updated version of count from my first function.



import threading, time
count = 0
def f1():
global count
while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()
return count


def f2():
clock = 1200 - count
p = 1
while True:
while p == 1:
if p == 1:
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
print("It seems you wont be able to get any clear information without inspecting each thing")
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
time.sleep(5)
desk = input("What do you do?")

if desk.lower() == ("inspect clock"):
print("You look up at the digital clock on the wall.")
print("Glowing red, the clock continues to count down.")
print("You seem to have", clock," seconds left")

elif desk.lower() == ("inspect box"):
print("After clear inspection of the box, you note that each of the buttons are a color of the rainbow")
print("However, you also notice that each button has a number written on it.")
print("The numbers and colors are as follows:")
print("'Red, 4 / Orange, 3 / Yellow, 6 / Green, 5 / Blue, 2 / Purple, 1")

elif desk.lower() == ("inspect paper"):
import Rainbow
print("Click the window to stop looking at the paper")

elif desk.lower() == ("get up"):
print("You find it impossible to move due to the chains wrapped around your legs.")
print("There is also a lock sitting on your lap, preventing you from removing the chain.")

elif desk.lower() == ("inspect lock"):
print("It is a lock, no key attached though")

elif desk.lower() ==("solve box"):
box = input("What is the solution? R=4,O=3,Y=6,G=5,B=2,P=1")
if box.lower() == ("43621"):
p = 2
else:
print("The box does nothing, mustve been the wrong combination")


else:
print("Invalid input. Retry.")



threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Basically I want to be able to use the input "inspect clock" and get the updated count from the timer function. This is probably a silly question, apologies if it is.










share|improve this question

























  • You have a local and a global version of the count variable.

    – Klaus D.
    Nov 22 '18 at 4:00











  • Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

    – Nick Offenberger
    Nov 22 '18 at 4:03














2












2








2








I am working on a final project for my python class and I have been desperately attempting to get these two processes to run at the same time, but when I run them I get no responses from either functions.



import threading, time
count = 0
clock = 1200 - count
def f1():

while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()

def f2():
pass

threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Apologies if this is a silly question, I just cant seem to get anything to work and I just want to be able to take reference from the timer in the first function from the second function during play.
Also to give some context, in the second function I am creating an escape room that will use the first function to check how much time they have left to escape.





Basically now I incorporated a section to the second part of my function to test and see if I could pull information from my first function to the second. This time both programs worked well simultaneously but due to my noob level knowledge when it comes to python, I wasn't sure how I would be able to get the updated version of count from my first function.



import threading, time
count = 0
def f1():
global count
while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()
return count


def f2():
clock = 1200 - count
p = 1
while True:
while p == 1:
if p == 1:
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
print("It seems you wont be able to get any clear information without inspecting each thing")
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
time.sleep(5)
desk = input("What do you do?")

if desk.lower() == ("inspect clock"):
print("You look up at the digital clock on the wall.")
print("Glowing red, the clock continues to count down.")
print("You seem to have", clock," seconds left")

elif desk.lower() == ("inspect box"):
print("After clear inspection of the box, you note that each of the buttons are a color of the rainbow")
print("However, you also notice that each button has a number written on it.")
print("The numbers and colors are as follows:")
print("'Red, 4 / Orange, 3 / Yellow, 6 / Green, 5 / Blue, 2 / Purple, 1")

elif desk.lower() == ("inspect paper"):
import Rainbow
print("Click the window to stop looking at the paper")

elif desk.lower() == ("get up"):
print("You find it impossible to move due to the chains wrapped around your legs.")
print("There is also a lock sitting on your lap, preventing you from removing the chain.")

elif desk.lower() == ("inspect lock"):
print("It is a lock, no key attached though")

elif desk.lower() ==("solve box"):
box = input("What is the solution? R=4,O=3,Y=6,G=5,B=2,P=1")
if box.lower() == ("43621"):
p = 2
else:
print("The box does nothing, mustve been the wrong combination")


else:
print("Invalid input. Retry.")



threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Basically I want to be able to use the input "inspect clock" and get the updated count from the timer function. This is probably a silly question, apologies if it is.










share|improve this question
















I am working on a final project for my python class and I have been desperately attempting to get these two processes to run at the same time, but when I run them I get no responses from either functions.



import threading, time
count = 0
clock = 1200 - count
def f1():

while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()

def f2():
pass

threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Apologies if this is a silly question, I just cant seem to get anything to work and I just want to be able to take reference from the timer in the first function from the second function during play.
Also to give some context, in the second function I am creating an escape room that will use the first function to check how much time they have left to escape.





Basically now I incorporated a section to the second part of my function to test and see if I could pull information from my first function to the second. This time both programs worked well simultaneously but due to my noob level knowledge when it comes to python, I wasn't sure how I would be able to get the updated version of count from my first function.



import threading, time
count = 0
def f1():
global count
while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()
return count


def f2():
clock = 1200 - count
p = 1
while True:
while p == 1:
if p == 1:
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
print("It seems you wont be able to get any clear information without inspecting each thing")
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
time.sleep(5)
desk = input("What do you do?")

if desk.lower() == ("inspect clock"):
print("You look up at the digital clock on the wall.")
print("Glowing red, the clock continues to count down.")
print("You seem to have", clock," seconds left")

elif desk.lower() == ("inspect box"):
print("After clear inspection of the box, you note that each of the buttons are a color of the rainbow")
print("However, you also notice that each button has a number written on it.")
print("The numbers and colors are as follows:")
print("'Red, 4 / Orange, 3 / Yellow, 6 / Green, 5 / Blue, 2 / Purple, 1")

elif desk.lower() == ("inspect paper"):
import Rainbow
print("Click the window to stop looking at the paper")

elif desk.lower() == ("get up"):
print("You find it impossible to move due to the chains wrapped around your legs.")
print("There is also a lock sitting on your lap, preventing you from removing the chain.")

elif desk.lower() == ("inspect lock"):
print("It is a lock, no key attached though")

elif desk.lower() ==("solve box"):
box = input("What is the solution? R=4,O=3,Y=6,G=5,B=2,P=1")
if box.lower() == ("43621"):
p = 2
else:
print("The box does nothing, mustve been the wrong combination")


else:
print("Invalid input. Retry.")



threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


Basically I want to be able to use the input "inspect clock" and get the updated count from the timer function. This is probably a silly question, apologies if it is.







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 4:32







Nick Offenberger

















asked Nov 22 '18 at 3:57









Nick OffenbergerNick Offenberger

112




112













  • You have a local and a global version of the count variable.

    – Klaus D.
    Nov 22 '18 at 4:00











  • Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

    – Nick Offenberger
    Nov 22 '18 at 4:03



















  • You have a local and a global version of the count variable.

    – Klaus D.
    Nov 22 '18 at 4:00











  • Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

    – Nick Offenberger
    Nov 22 '18 at 4:03

















You have a local and a global version of the count variable.

– Klaus D.
Nov 22 '18 at 4:00





You have a local and a global version of the count variable.

– Klaus D.
Nov 22 '18 at 4:00













Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

– Nick Offenberger
Nov 22 '18 at 4:03





Literally I just made that realization like 30 seconds ago, I am retarded. Also, now I have the issue that I cant seem to access the count variable from the first function to use within the second function

– Nick Offenberger
Nov 22 '18 at 4:03












2 Answers
2






active

oldest

votes


















0














You need to let Python know that you're referring to the global count in pass. To do this, you just need to use the global keyword. Try this:



import threading, time
count = 0
clock = 1200 - count
def f1():
global count
while True:
if count < 1200:
time.sleep(1)
count += 1
print(count)
else:
exit()

def f2():
pass

threading.Thread(target=f1).start()
threading.Thread(target=f2).start()


When you reference count in f2, you do not need to use the global keyword. You can test this out by replacing f2 with the following:



def f2():
while True:
time.sleep(1)
print(count)





share|improve this answer































    0














    Global variables are worth avoiding, but the below at least demonstrates that the bulk of your code is correct. I'm not sure what you're trying to do with clock so I commented it out. But this returns output from both functions.



    import threading, time

    count = 0
    # clock = 1200 - count

    def f1():
    global count
    while True:
    if count < 1200:
    time.sleep(1)
    count += 1
    print(count)
    else:
    exit()

    def f2():
    global count
    while True:
    print('f2():',count)
    time.sleep(1)

    threading.Thread(target=f1).start()
    threading.Thread(target=f2).start()





    share|improve this answer
























    • Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

      – Nick Offenberger
      Nov 22 '18 at 4:35











    • There are a number of issues with your edit, but your reference to clock in the line you have will work.

      – directive-41
      Nov 22 '18 at 5:43













    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%2f53423663%2fi-cant-seem-to-get-any-response-when-attempting-to-run-these-two-functions-simul%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









    0














    You need to let Python know that you're referring to the global count in pass. To do this, you just need to use the global keyword. Try this:



    import threading, time
    count = 0
    clock = 1200 - count
    def f1():
    global count
    while True:
    if count < 1200:
    time.sleep(1)
    count += 1
    print(count)
    else:
    exit()

    def f2():
    pass

    threading.Thread(target=f1).start()
    threading.Thread(target=f2).start()


    When you reference count in f2, you do not need to use the global keyword. You can test this out by replacing f2 with the following:



    def f2():
    while True:
    time.sleep(1)
    print(count)





    share|improve this answer




























      0














      You need to let Python know that you're referring to the global count in pass. To do this, you just need to use the global keyword. Try this:



      import threading, time
      count = 0
      clock = 1200 - count
      def f1():
      global count
      while True:
      if count < 1200:
      time.sleep(1)
      count += 1
      print(count)
      else:
      exit()

      def f2():
      pass

      threading.Thread(target=f1).start()
      threading.Thread(target=f2).start()


      When you reference count in f2, you do not need to use the global keyword. You can test this out by replacing f2 with the following:



      def f2():
      while True:
      time.sleep(1)
      print(count)





      share|improve this answer


























        0












        0








        0







        You need to let Python know that you're referring to the global count in pass. To do this, you just need to use the global keyword. Try this:



        import threading, time
        count = 0
        clock = 1200 - count
        def f1():
        global count
        while True:
        if count < 1200:
        time.sleep(1)
        count += 1
        print(count)
        else:
        exit()

        def f2():
        pass

        threading.Thread(target=f1).start()
        threading.Thread(target=f2).start()


        When you reference count in f2, you do not need to use the global keyword. You can test this out by replacing f2 with the following:



        def f2():
        while True:
        time.sleep(1)
        print(count)





        share|improve this answer













        You need to let Python know that you're referring to the global count in pass. To do this, you just need to use the global keyword. Try this:



        import threading, time
        count = 0
        clock = 1200 - count
        def f1():
        global count
        while True:
        if count < 1200:
        time.sleep(1)
        count += 1
        print(count)
        else:
        exit()

        def f2():
        pass

        threading.Thread(target=f1).start()
        threading.Thread(target=f2).start()


        When you reference count in f2, you do not need to use the global keyword. You can test this out by replacing f2 with the following:



        def f2():
        while True:
        time.sleep(1)
        print(count)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 4:09









        Unsolved CypherUnsolved Cypher

        510315




        510315

























            0














            Global variables are worth avoiding, but the below at least demonstrates that the bulk of your code is correct. I'm not sure what you're trying to do with clock so I commented it out. But this returns output from both functions.



            import threading, time

            count = 0
            # clock = 1200 - count

            def f1():
            global count
            while True:
            if count < 1200:
            time.sleep(1)
            count += 1
            print(count)
            else:
            exit()

            def f2():
            global count
            while True:
            print('f2():',count)
            time.sleep(1)

            threading.Thread(target=f1).start()
            threading.Thread(target=f2).start()





            share|improve this answer
























            • Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

              – Nick Offenberger
              Nov 22 '18 at 4:35











            • There are a number of issues with your edit, but your reference to clock in the line you have will work.

              – directive-41
              Nov 22 '18 at 5:43


















            0














            Global variables are worth avoiding, but the below at least demonstrates that the bulk of your code is correct. I'm not sure what you're trying to do with clock so I commented it out. But this returns output from both functions.



            import threading, time

            count = 0
            # clock = 1200 - count

            def f1():
            global count
            while True:
            if count < 1200:
            time.sleep(1)
            count += 1
            print(count)
            else:
            exit()

            def f2():
            global count
            while True:
            print('f2():',count)
            time.sleep(1)

            threading.Thread(target=f1).start()
            threading.Thread(target=f2).start()





            share|improve this answer
























            • Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

              – Nick Offenberger
              Nov 22 '18 at 4:35











            • There are a number of issues with your edit, but your reference to clock in the line you have will work.

              – directive-41
              Nov 22 '18 at 5:43
















            0












            0








            0







            Global variables are worth avoiding, but the below at least demonstrates that the bulk of your code is correct. I'm not sure what you're trying to do with clock so I commented it out. But this returns output from both functions.



            import threading, time

            count = 0
            # clock = 1200 - count

            def f1():
            global count
            while True:
            if count < 1200:
            time.sleep(1)
            count += 1
            print(count)
            else:
            exit()

            def f2():
            global count
            while True:
            print('f2():',count)
            time.sleep(1)

            threading.Thread(target=f1).start()
            threading.Thread(target=f2).start()





            share|improve this answer













            Global variables are worth avoiding, but the below at least demonstrates that the bulk of your code is correct. I'm not sure what you're trying to do with clock so I commented it out. But this returns output from both functions.



            import threading, time

            count = 0
            # clock = 1200 - count

            def f1():
            global count
            while True:
            if count < 1200:
            time.sleep(1)
            count += 1
            print(count)
            else:
            exit()

            def f2():
            global count
            while True:
            print('f2():',count)
            time.sleep(1)

            threading.Thread(target=f1).start()
            threading.Thread(target=f2).start()






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 4:10









            directive-41directive-41

            989




            989













            • Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

              – Nick Offenberger
              Nov 22 '18 at 4:35











            • There are a number of issues with your edit, but your reference to clock in the line you have will work.

              – directive-41
              Nov 22 '18 at 5:43





















            • Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

              – Nick Offenberger
              Nov 22 '18 at 4:35











            • There are a number of issues with your edit, but your reference to clock in the line you have will work.

              – directive-41
              Nov 22 '18 at 5:43



















            Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

            – Nick Offenberger
            Nov 22 '18 at 4:35





            Alright well I hope you see this but I incorporated in an edit what the clock variable was for, I cant seem to figure out how to obtain the updated count for my second function.

            – Nick Offenberger
            Nov 22 '18 at 4:35













            There are a number of issues with your edit, but your reference to clock in the line you have will work.

            – directive-41
            Nov 22 '18 at 5:43







            There are a number of issues with your edit, but your reference to clock in the line you have will work.

            – directive-41
            Nov 22 '18 at 5:43




















            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%2f53423663%2fi-cant-seem-to-get-any-response-when-attempting-to-run-these-two-functions-simul%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?