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

import	time
from	multiprocessing	import	Process

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

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


# print '*' @ 0.5 Sec
def task2():
    while True:
        print('*', end='')
        time.sleep(0.5)


# print '.' @ 0.25 Sec
def task3():
    while True:
        print('.', end='')
        time.sleep(0.25)


# main loop executing task1, task2 and task3
def main():
    p1 = Process(target=task1, args=()); p1.start()
    p2 = Process(target=task2, args=()); p2.start()
    p3 = Process(target=task3, args=()); p3.start()
    time.sleep(10)
    p1.terminate(); p2.terminate(); p3.terminate()
    time.sleep(2)
    print('\nmain terminated')


main()

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