#!/usr/bin/env python3

import time                # time manipulation, sleeping
import threading as thr    # threading
 
# a random target task function
def taskFuntion(message):
#   time.sleep(3.0)                           # test it
    print(message)
 
#
# thread timer object invokes a task function with arguments
#
timer = thr.Timer(3, taskFuntion, args=('timer function executed',))
timer.start()

# counting while waiting for the timer to finish
counting = 0
while (timer.is_alive()):                     # try with 'not'
  time.sleep(0.3)                             # sleeping in seconds
  counting += 1
  print("counting while waiting ", counting)

# cancel the thread
if (timer.is_alive()):
  print('canceling the timer')
  timer.cancel()
