py_thread.py

来自「unix下解释类c++语言的封装类」· Python 代码 · 共 31 行

PY
31
字号
''' Demonstrate the use of python threading'''

import time
import threading

def ThreadFunc():
	for i in range(15):
		print '...Printed from my thread.'
		time.sleep(1)

class MyThread(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
	def run(self):
		for i in range(15):
			print 'printed from MyThread...'
			time.sleep(1)

def createThread():
	print 'Create and run MyThread'
	background = MyThread()
	background.start()
	print  'Main thread continues to run in foreground.'
	for i in range(10):
		print 'printed from Main thread.'
		time.sleep(1)
	print  'Main thread joins MyThread and waits until it is done...'
	background.join() # Wait for the background task to finish
	print  'The program completed gracefully.'
	
	return 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?