相关疑难解决方法(0)

为什么我在Python中使用Thread获取TypeError

我有以下代码,这是基于我在这里找到的一个例子,但是当我运行它时,我得到一个错误.请帮忙,我确定它非常简单:

def listener(port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.bind(('',port))
    sock.settimeout(1) # n second(s) timeout
    try:
        while True:
            data, addr = sock.recvfrom(1024)
            print data
    except socket.timeout:
        print 'Finished'

def startListenerThread(port):
    threading.Thread(target=listener, args=(port)).start()
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
TypeError: listener() argument after * must be a sequence, not int
Run Code Online (Sandbox Code Playgroud)

python multithreading

17
推荐指数
3
解决办法
2万
查看次数

标签 统计

multithreading ×1

python ×1