2020
09-27
09-27
Python 多线程共享变量的实现示例
多线程-共享全局变量#coding=utf-8fromthreadingimportThreadimporttimeg_num=100defwork1():globalg_numforiinrange(3):g_num+=1print("----inwork1,g_numis%d---"%g_num)defwork2():globalg_numprint("----inwork2,g_numis%d---"%g_num)print("---线程创建之前g_numis%d---"%g_num)t1=Thread(target=work1)t1.start()#延时一会,保证t1线程中的事情做完time.sleep(1)t2=Thread(target=work2...
继续阅读 >