def main():
print '\nStarting: ........', time.strftime('%Y-%M-%d %H:%m:%S'), '\n'
mysec = [3,5,6,8]
mythreads = [threading.Thread(target=loop,args=(i,mysec)) for i in range(len(mysec))]
for i in mythreads:
i.start()
for i in mythreads:
i.join()
print '\nAll DONE: ........', time.strftime('%Y-%M-%d %H:%m:%S'), '\n'
if __name__=='__main__':
main()
执行结果:
[iyunv@xhu_node3 ~]# python mutithread.py
#!/usr/bin/python
import os
import sys
import time, datetime, traceback
from os import environ
from multiprocessing import Process
from test import MyClass
def create_compute(hostname):
try:
environ['FOO'] = hostname
a = MyClass()
print a.getA()
except Exception as e:
print e
traceback.print_exc()
if __name__ == '__main__':
plist = []
for i in 4,5:
p = Process(target = create_compute, args = ('node'+str(i),))
plist.append(p);
p.start()
for p in plist:
p.join()
执行结果:
[iyunv@xhu_node3 ~]# python pro.py