1、验证码生成案例:
#!/usr/bin/env pythonimport randomcode=[]for i in range(6): if i == random.randint(1,5): code.append(str(random.randint(1,9))) else: temp = random.randint(65,90) code.append(chr(temp)) #chr转化成字母print(''.join(code)) #格式化成字符串
2、线程和进程对比
from multiprocessing import Process,Queueimport threadingdef run(info_list,n): info_list.append(n) print(info_list)info = []if __name__ == '__main__': for i in range(12): p = Process(target=run,args=[info,i]) p.start()print('--------------------------')if __name__ == '__main__': for i in range(12): p = threading.Thread(target=run, args=[info, i]) p.start()