파이썬[Python]: threading - start 메서드

파이썬(Phthon): threading 모듈 - start 함수(function)


/// 설명

스레드를 동작시킵니다. 스레드 객체당 한번만 불리어져야 하며, 객체의 run() 메서드를 조정합니다.

※ 형식
start()

reference
https://docs.python.org/3/library/threading.html#module-threading

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import threading
import datetime
import time
 
 
def test_thread(i):
    print(f'   ---> test_thread {i} is started!')
    time.sleep(i)
    print(f'   {i}: test_thread - sleep({i}) ---')
    print('   ---> Time:', datetime.datetime.now().time())
 
 
print('---> Time:', datetime.datetime.now().time())
t1 = threading.Thread(target=test_thread, args=(1,))
t1.start()
t2 = threading.Thread(target=test_thread, args=(2,))
t2.start()
print('---> Time:', datetime.datetime.now().time())
print('-' * 50)
 
# ---> Time: 21:03:18.894737
#    ---> test_thread 1 is started!
#    ---> test_thread 2 is started!
# ---> Time: 21:03:18.894737
# --------------------------------------------------
#    1: test_thread - sleep(1) ---
#    ---> Time: 21:03:19.905582
#    2: test_thread - sleep(2) ---
#    ---> Time: 21:03:20.905804
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수