Created
May 18, 2017 01:02
-
-
Save nattybear/f4ed6b775e3f57171a6520afac01eba6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
def say(msg): | |
while True: | |
time.sleep(1) | |
print(msg) | |
for msg in ['you', 'need', 'python']: | |
t = threading.Thread(target=say, args=(msg,)) | |
t.daemon = True | |
t.start() | |
for i in range(100): | |
time.sleep(0.1) | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sleep 함수
sleep 함수는 인자로 받은 수의 초만큼 동작을 멈추는 거야
예를 들어서 sleep(10)을 실행하면 파이썬이 10초 동안 동작을 멈추지
다음과 같은 상황에서 사용 할 수 있어
화면에 "Hello" 라는 문자열을 1초에 한번씩 10번 출력하고 싶다면 아래와 같이 하면 돼
Thread
"쓰레드"라고 보통 발음하는데 이건 글로 설명하기 보다는 스카이프로 예제와 함께 설명해줄게!
예고를 하자면
코드는 보통 위에서 아래로 차례대로 실행되는데
쓰레드를 이용하면 두가지 이상의 작업을 동시에 하는 것 처럼 할 수 있어 ㅎ