标题基本上说明了一切。如果您在Python 3.6.5中运行此代码:
from threading import Thread
import numpy as np
import time
# function doesn't return anything
def do_stuff(x):
x += 5
x = np.random.randint(256, size=(100,100), dtype=np.uint8)
Thread(target=do_stuff, args=(x), name="my thread").start()
time.sleep(1)
您收到以下错误:
Exception in thread my thread:
Traceback (most recent call last):
File "/home/username/anaconda3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/username/anaconda3/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: do_stuff() takes 1 positional argument but 100 were given
由于某种原因,numpy数组似乎正在扩展,这对我来说是极其出乎意料的行为。有人可以解释为什么会这样吗,并给我一个解决方法吗?
谢谢!