diff --git a/cookbook/c12/p01_start_stop_thread.py b/cookbook/c12/p01_start_stop_thread.py index f1f8ebf..3145103 100644 --- a/cookbook/c12/p01_start_stop_thread.py +++ b/cookbook/c12/p01_start_stop_thread.py @@ -1,5 +1,6 @@ - +import socket import time + def countdown(n): while n > 0: print('T-minus', n) @@ -12,10 +13,7 @@ t = Thread(target=countdown, args=(10,)) t.start() -if t.is_alive(): - print('Still running') -else: - print('Completed') +print('Still running' if t.is_alive() else 'Completed') t.join() @@ -82,4 +80,4 @@ c.start() import multiprocessing c = CountdownTask(5) p = multiprocessing.Process(target=c.run) -p.start() \ No newline at end of file +p.start()