#进程:Process 计算密集型
#线程:Thread 耗时操作时使用,爬虫
#状态:新建,就绪,运行,阻塞,结束
# 线程是可以共享全局变量的
# GIL 全局解释器锁
import threading
money=1000
ticket=1000
'''
线程是可以共享全局变量的
GIL 全局解释器锁
'''
def run1():
global ticket
for i in range(100):
ticket-=1
def run2():
global money
for i in range(100):
money-=1
if __name__=="__main__":
th1=threading.Thread(target=run1,name='th1')
th2=threading.Thread(target=run1,name='th2')
th3=threading.Thread(target=run1,name='th3')
th4=threading.Thread(target=run1,name='th4')
th5=threading.Thread(target=run2,name='th5')
th1.start()
th2.start()
th3.start()
th4.start()
th5.start()
th1.join()
th2.join()
th3.join()
th4.join()
th5.join()
print('money:',money)
print('ticket:',ticket)
import threading
n=0
def task1():
global n
for i in range(10000000000):
n+=1
print('----->task1中的值是:',n)
def task2():
global n
for i in range(10000000000):
n+=1
print('----->task2中值是:',n)
if __name__ == '__main__':
th1=threading.Thread(target=task1,name='task1')
th2=threading.Thread(target=task2,name='task2')
th1.start()
th2.start()
th1.join()
th2.join()
print('n最后值是:',n)
作业
import sysfrom PySide6.QtWidgets import QApplication, QWidget,QPushButton,QLineEditfrom Form import Ui_Form
from second import Ui_second
from PySide6.QtCore import Qtclass MyWidget(QWidget,Ui_Form):def __init__(self):super().__init__()self.setupUi(se…