from threading import Thread import time class MyThread(Thread): def __init__(self,name): super().__init__() self.name = name def run(self): print("%s is running"%self.name) if __name__ == '__main__': t = MyThread('wu') t.start()
线程代码如下:线程相当于是在资源单位内的workker ,就像是nginx一个master进程多个worker
from threading import Thread import time class MyThread(Thread): def __init__(self,name): super().__init__() self.name = name def run(self): print("%s is running"%self.name) def run(*args): print("xxxx") if __name__ == '__main__': t = MyThread('wu') t.start() t2 =Thread(target=run,args=(1,)) t2.start()
进程:资源代码
def run(*args): print("xxxx") # if __name__ == '__main__': # t = MyThread('wu') # t.start() # t2 =Thread(target=run,args=(1,)) # t2.start() from multiprocessing import Process if __name__ == '__main__': p = Process(target=run,args=(1,)) p.start()
from threading import Thread
import time
class MyThread(Thread):
def __init__(self,name):
super().__init__()
self.name = name
def run(self):
print("%s is running"%self.name)
if __name__ == '__main__':
t = MyThread('wu')
t.start()