1. 멀티 스레드란?
- 하나의 프로세스 안에 동시에 작업이 진행되어야 하는 경우 매우 빠르게 번갈아가면서 작업을 실행하여 거시적으로는 동시에 여러가지 작업을 진행하는 것(동시성)
2. 멀티 프로세스란?
- 코어를 여러개 사용하여 실제로 동시에 작업을 진행하는 것(병렬성)
3. 멀티 스레드 사용 방법
import threading
import time
def creator():
print('---생성---')
time.sleep(1)
def consumer():
print('---사용완료---')
time.sleep(1)
print('메인작업')
creator = threading.Thread(target=creator)
consumer = threading.Thread(target=consumer)
creator.start()
consumer.start()
creator.join() #작업이 끝날 때까지 기다림
consumer.join()
print('작업종료')
'Python > Language' 카테고리의 다른 글
[Python] 예외처리 (1) | 2024.01.23 |
---|---|
[python] 튜플 과 SET (0) | 2024.01.23 |
[python] 정규표현식(Regex) (0) | 2023.08.17 |
[python] 함수 (0) | 2023.08.15 |
[python] 메모리 할당과 복사 (0) | 2023.08.10 |