Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread not Working
#1
Thumbs Down 
I've created a CLI little adventure game written in Python. I've defined a function that returns False whether time.sleep() is done and then I created a thread that allows the user to input the answer while self.is_time_elapsed() is True. Here's the code:
    def if_time_elapsed(self,clock):
        time.sleep(clock)
        return False

    def main(self):
        while self.run:
            self.start_game()
            os.system('clear')
            print(Game.ascii_header)
            print(f'Welcome to this Adventure {self.usr_name}!') 
            time.sleep(2)
            print('<START STORY>\nA terrible Iceberg destroyed the cruise ship you had taken enjoying the holidays,\n you ended up in the water at the mercy of the waves and you have to save yourself. ')
            print('\n<You\'ve got 10 seconds to write out the word "CLING" to cling to a rock.>')
            t_timer = threading.Thread(target=self.if_time_elapsed,args=(10,))
            t_timer.start()
            while t_timer:
                usr_input = input('> ').lower().strip()
                if usr_input != 'cling':
                    print("SCRRRR! Wrong answer!")
The problem is that basically the program keeps asking the input without closing after timeout. I also tried with t_timer.run() insted of t_timer.start() but nothing.
Reply


Messages In This Thread
Thread not Working - by michaelserra - Aug-01-2021, 02:46 PM
RE: Thread not Working - by deanhystad - Aug-01-2021, 04:22 PM
RE: Thread not Working - by michaelserra - Aug-03-2021, 11:12 AM
RE: Thread not Working - by deanhystad - Aug-03-2021, 02:52 PM
RE: Thread not Working - by michaelserra - Aug-04-2021, 10:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error SQLite objects created in a thread can only be used in that same thread. binhduonggttn 3 15,657 Jan-31-2020, 11:08 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020