start_new_thread用法
时间: 2023-11-26 12:02:41 浏览: 30
plt.plot(gen, fit_maxs, label="Maximum Fitness")
plt.xlabel("Generation")
plt.ylabel("Fitness")
plt`start_new_thread` 是 Python 中的一个函数,用于创建并启动一个新的线程。它的用法如.legend(loc="lower right")
plt.show()
```
运行结果:
```
gen avg min max
0 下:
```python
import _thread
def function_name(arg1, arg2, ...):
# 线程执行的代码
#-111.075 -202.047 -38.0735
1 -33.5808 -123.448 创建并启动一个新的线程
_thread.start_new_thread(function_name, (arg1, arg2, ...))
```
其中 15.1489
2 -6.33745 -37.4442 9.18133
3 ,`function_name` 是需要在新线程中执行的函数,`arg1, arg2, ...` 是传递给1.2027 -7.97096 9.18133
4 3.69194 -1.函数的参数。注意,参数必须以元组的形式传递。在调用 `start_new_thread` 函数时,32454 9.18133
5 4.97176 -0.58309 9.18133
6它会返回一个整数,表示新线程的标识符。可以使用这个标识符来操作新线程, 5.74168 -0.58309 9.18133
7 6.19887 -例如等待它结束等。需要注意的是,在新线程中执行的函数必须是线程安全的,否则可能会引发竞态条件等问题。