27 lines
433 B
Python
27 lines
433 B
Python
|
|
# main.py -- run after boot.py
|
||
|
|
|
||
|
|
import _thread
|
||
|
|
import time
|
||
|
|
|
||
|
|
|
||
|
|
def count(name: str, stop: int = 10):
|
||
|
|
i = 0
|
||
|
|
|
||
|
|
while True:
|
||
|
|
print("[{}] {}".format(name, i))
|
||
|
|
i += 1
|
||
|
|
|
||
|
|
if i > stop:
|
||
|
|
break
|
||
|
|
|
||
|
|
time.sleep(1)
|
||
|
|
|
||
|
|
print("[{}] exit".format(name))
|
||
|
|
|
||
|
|
# Start some threads
|
||
|
|
_thread.start_new_thread(count, ('thread1', 5))
|
||
|
|
_thread.start_new_thread(count, ('thread2', 3))
|
||
|
|
|
||
|
|
# Main thread
|
||
|
|
count('main', 10)
|