Multithreading 多线程函数正好接受6个参数(给定0个)错误

Multithreading 多线程函数正好接受6个参数(给定0个)错误,multithreading,python-2.7,Multithreading,Python 2.7,我已经创建了简单线程函数,但我得到一个错误,即即使我已经传递了所有6个参数,也传递了0个参数。我尝试过使用args和kwargs,但仍然有相同的错误 下面是我的代码 import time import datetime import threading def get_time(): datestart = datetime.datetime.now() - datetime.timedelta(minutes = 60) dateend = datetime.datetim

我已经创建了简单线程函数,但我得到一个错误,即即使我已经传递了所有6个参数,也传递了0个参数。我尝试过使用args和kwargs,但仍然有相同的错误

下面是我的代码

import time
import datetime
import threading

def get_time():
    datestart = datetime.datetime.now() - datetime.timedelta(minutes = 60)
    dateend = datetime.datetime.now()
    timeprevious = int(time.mktime(datestart.timetuple()) * 1000)
    timenow = int(time.mktime(dateend.timetuple()) * 1000)
    return timeprevious, timenow

def customer(src_ip,dst_ip,host_ip,index_name,timeprevious,timenow):
  print(src_ip)
  print(dst_ip)
  print(host_ip)
  print(index_name)
  print(timeprevious)
  print(timenow)

host_name = ['host_name1', 'host_name2', 'host_name3']
host_ip = ['host_ip1', 'host_ip2', 'host_ip3']
index_name = ['index_name1',' index_name2', 'index_name3']
src_ip = ['Src_IP', 'source_ip', 'SourceAddress']
dst_ip = ['Dst_IP', 'destination_ip', 'DestinationAddress']

timeprevious, timenow = get_time()

threads = []                                                                
for i in range(len(host_name)):
  try:
    # t = threading.Thread(target=customer(), args=(src_ip[i],dst_ip[i],host_ip[i],index_name[i],timeprevious,timenow))
    t = threading.Thread(target=customer(), kwargs={'src_ip': src_ip[i],'dst_ip':dst_ip[i],'host_ip': host_ip[i],'index_name': index_name[i],'timeprevious': timeprevious,'timenow': timenow })

    threads.append(t)
    t.start()
  except Exception as e:
    print('error ' + host_name[i])
    print(e)

for t in threads:                                                           
  t.join()
这就是我所犯的错误
customer()只接受6个参数(给定0个)
。您可以在评论中看到,我也使用kwargs来解决错误,但我没有运气。这也是传递多个参数的正确方法吗

您在以下行遇到问题:

t = threading.Thread(target=customer(), kwargs={'src_ip': src_ip[i],'dst_ip':dst_ip[i],'host_ip': host_ip[i],'index_name': index_name[i],'timeprevious': timeprevious,'timenow': timenow })*emphasized text*

target=customer()
将目标函数的值设置为调用
customer()
的返回值。要传递对客户函数的引用,请使用
target=customer

,它应该是
target=customer
(一个包含6个参数的函数对象),而不是
target=customer()
(即
None
)。@CedricH。非常感谢您的快速响应。它解决了我的问题。