python에서 thread 사용하기

이상해씨·2023년 8월 16일
0

스레드 (Thread)

목록 보기
2/2

thread 설정하기

1. thread import하기

import threading
import time 
# 시뮬레이션을 위한 대기 설정 목적

2. thread 생성 및 주기적으로 실행할 코드 작성

  • 예시 코드
def my_job():
    print("Starting job...")
    time.sleep(5)  # 작업 시뮬레이션을 위해 5초 대기
    # 코드 내용 자유롭게 기술
    print("Job completed!")

3. thread 생성

my_thread = threading.Thread(target=my_job)

4. 스레드 실행

my_thread.start()

print("Main thread continues while the background thread is running...")

참고

  • chat GPT
profile
공부에는 끝이 없다

1개의 댓글

comment-user-thumbnail
2023년 8월 16일

큰 도움이 되었습니다, 감사합니다.

답글 달기