E D R , A S I H C RSS

Python Multi Threading

Python ์—์„œ๋Š” 2๊ฐ€์ง€ thread interface ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ํ•˜๋‚˜๋Š” C ์Šคํƒ€์ผ์˜ API ๋ฅผ, ํ•˜๋‚˜๋Š” Java ์Šคํƒ€์ผ์˜ Thread Object๋ฅผ.

์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋งค์šฐ ๊ฐ„๋‹จ. Thread class ๋ฅผ ์ƒ์†๋ฐ›์€๋’ค Java ์ฒ˜๋Ÿผ start ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ๋ฉด run ๋ฉ”์†Œ๋“œ์— ๊ตฌํ˜„๋œ ๋‚ด์šฉ์ด multithread ๋กœ ์‹คํ–‰๋œ๋‹ค.

๋‹ค์Œ์€ ๊ฐ„๋‹จํ•œ ์˜ˆ.
~cpp 
import thread
import time

def runOne(args):
	i = 0
	while(1):
		i = i+1
		print "thread : ", i, args
		time.sleep(1)


if __name__=="__main__":
	thread.start_new_thread(runOne, ((1,)))

	for i in range(100000,0,-1):
		print "waiting: ", i
		time.sleep(1)

๋‹ค๋ฅธ ์ฐจ์›์˜ ๊ธฐ๋ฒ•์œผ๋กœ๋Š” Seminar:LightWeightThreads๊ฐ€ ์žˆ๋‹ค.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:24:08
Processing time 0.0148 sec