# cPy - demonstrating pre-emptive multitasking
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 010  2025-10-06  initial release

import	time
from	_thread	import	start_new_thread

# ============================== demo ===============================

terminated = False


# print '@' @ 1 Sec
def task1():
    try:
        while not terminated:
            print('@', end='')
            time.sleep(1)
    finally: print('task1 terminated')


# print '*' @ 0.5 Sec
def task2():
    try:
        while not terminated:
            print('*', end='')
            time.sleep(0.5)
    finally: print('task2 terminated')


# print '.' @ 0.25 Sec
def task3():
    try:
        while not terminated:
            print('.', end='')
            time.sleep(0.25)
    finally: print('task3 terminated')


# main loop executing task1, task2 and task3
def main():
    global	terminated
    
    start_new_thread(task1, ())
    start_new_thread(task2, ())
    start_new_thread(task3, ())
    time.sleep(10)
    terminated = True
    print('\nmain terminated')


main()

# ============================== end ===============================
