好的。所以我试图让 2 个线程运行并增加一个值,以便它知道何时停止。我有点迷路了,因为我是 Python 新手,对我来说一切都很好..
import threading;
import socket;
import time;
count = 0;
class inp(threading.Thread):
def run(self):
while count < 11:
time.sleep(0.5);
print("Thread 1!");
count += 1;
class recv_oup(threading.Thread):
def run(self):
while count < 31:
time.sleep(0.5);
print("Thread 2!");
count += 1;
inp().start();
recv_oup().start();
而且错误很长...
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "core.py", line 9, in run
while count < 11:
UnboundLocalError: local variable 'count' referenced before assignment
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "core.py", line 16, in run
while count < 31:
UnboundLocalError: local variable 'count' referenced before assignment
我不知道发生了什么。正如我所说,Python 新手,所以这对我来说都是胡言乱语。任何帮助是极大的赞赏