multithreading - 类型错误 : req_con() takes 1 positional argument but 12 were given

标签 multithreading zeromq python-multithreading pyzmq

基本上,我试图返回在函数中获得的 IP 地址,并将其作为参数传递给另一个函数。由于它是一个 ip 地址,它给了我一个如上所述的错误。还有其他方法可以让它变得更好吗?

这是代码:

import zmq
import time
import socket
import threading
import multiprocessing
from threading import Thread
def bd_recv():
    login to get ip

def req_con(host):
    context=zmq.Context()
    socket = context.socket(zmq.REQ)
    #address=host,port

    port=3233
    socket.connect("tcp://" "%s:%d" % ((host),port))
    print("sending request")
    socket.send_string("hey controller")
    msg=socket.recv(1024)
    print("received reply: %s" %msg)
class ThreadWithReturnValue(Thread):
    def __init__(self, group=None, target=None, name=None,
                 args=(), kwargs={}, Verbose=None):
        Thread.__init__(self, group, target, name, args, kwargs)
        self._return = None
    def run(self):
        print(type(self._target))
        if self._target is not None:
            self._return = self._target(*self._args,
                                                **self._kwargs)
    def join(self, *args):
        Thread.join(self, *args)
        return self._return
if __name__=='__main__':
    #t1=threading.Thread(target=bd_recv,name='bdrecv')
    t3 = ThreadWithReturnValue(target=bd_recv)
    #t1.start()
    t3.start()
    host=(t3.join())  --> The return ipaddress b is given as a host to other function 
    t2=threading.Thread(target=req_con,name='req',args=host,)  --> here it gives me the error as 12 is given 

    t2.start()

最佳答案

不幸的是,我确实犯了一个小错误,我需要改变的是:

t2=threading.Thread(target=req_con,name='req', args=(host,)) --> this brackets in the host has to be added

关于multithreading - 类型错误 : req_con() takes 1 positional argument but 12 were given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462631/

相关文章:

Python 在定义时取消引用闭包变量

java - AtomicInteger 不会同时递增

java - 怎么可能有竞争条件呢?

zeromq - 您知道使用ZeroMQ的任何项目吗?成功和失败的故事都很有值(value)。

c# - 用于在自定义缓冲区中接收以避免在每个帧/消息上创建新字节数组的 NetMQ API 是什么?

python - 提高 python 脚本的吞吐量

python - 多处理Python

java - 为什么我没有看到多个线程打印出重复值?

java - Dining Philosophers 代码中发生的饥饿

python - 多核 Python : multiprocessing Vs. zeroMQ?