#!/usr/bin/env python3

import threading    # omen est nomen
import time

class DeltaT:
 myTime = time.perf_counter()
 def diff():
   newTime = time.perf_counter()
   deltaTime = newTime - DeltaT.myTime
   DeltaT.myTime = newTime
   return deltaTime


def taskFunction(name):
  print(f'Thread {name:2d}: starting')
  time.sleep(3)
  print(f'Thread {name:2d}: finishing')


# blocks out-of-us access
if __name__ == "__main__":

  print(DeltaT.diff())
  print(f'Main  {DeltaT.diff():4.2f}  : before creating thread')
  x = threading.Thread(target=taskFunction, args=(1,))
  print(f'Main  {DeltaT.diff():4.2f}  : before running the thread')

  time.sleep(2)
  x.start()                  # can be started anywhere

  print(f'Main  {DeltaT.diff():4.2f}  : waiting for the thread to finish')
  x.join()                   # stop until thread is done
  print(f'Main  {DeltaT.diff():4.2f}  : all done')
