Created
May 18, 2017 10:30
-
-
Save nattybear/556b39779c2e97fd0849bde440a36c3e to your computer and use it in GitHub Desktop.
Python Multithreaded Programming
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 thread | |
| import time | |
| # Define a function for the thread | |
| def print_time(threadName, delay): | |
| count = 0 | |
| while count < 5: | |
| time.sleep(delay) | |
| count += 1 | |
| print "%s: %s" % (threadName, time.ctime(time.time())) | |
| # Create two threads as follows | |
| try: | |
| thread.start_new_thread(print_time, ("Thread-1", 2,)) | |
| thread.start_new_thread(print_time, ("Thread-2", 4,)) | |
| except: | |
| print "Error: unable to start thread" | |
| while 1: | |
| pass |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
새 쓰레드 시작하기
쓰레드를 실행하려면 thread 모듈의 다음 메서드를 사용한다.
thread.start_new_thread(function, args[, kwargs])이 메서드를 사용하면 윈도우와 리눅스에서 모두 효율적이고 빠르게 쓰레드를 실행 할 수 있다.