0
import time

def exitpro(t):
        a=0    
        while t>0:
            dotcount = (a % 3) + 1
            timer="Loading" + "." * dotcount + " " * (3 - dotcount)
            print(timer, end='\r', flush=True)
            time.sleep(0.5)
            t-=0.5
            a+=1


def countdown(t):
        while t:
            mins,secs=divmod(t,60)
            cdown="%02d:%02d"%(mins,secs)
            print(cdown,end='\r',flush=True)
            time.sleep(1)
            t-=1
    
t=int(input("enter time in seconds "))
countdown(t)
exitpro(t)

I want both the functions to run simultaneously. Is there any way to do that in python in jupyter?

  • Does this answer your question? [Python: Executing multiple functions simultaneously](https://stackoverflow.com/questions/18864859/python-executing-multiple-functions-simultaneously) – bobtho'-' Apr 10 '21 at 16:45

1 Answers1

0

You can use threading: First define these two methods in jupyter: Now you have to write the following code in a new block

Import threading
t = int(input("enter time in seconds "))
Thread1 =  threading.Thread(target=exitpro, args=(t,))
Thread2 =  threading.Thread(target=countdown, args=(t,))
Thread1.start()
Thread2.start()
Aditya Tripathi
  • 111
  • 1
  • 4
  • By this both the print statements overlap each other. The result is something like this '00:00ng.. 00:10Loading..' or this '00:00ng.'. I tried adding a blank line in one of the functions, but it led to some weird output. – Chandravo Bhattacharya Apr 11 '21 at 08:26