在Python中使用多线程运行Iperf服务器和客户端导致分段错误
问题描述:
主类调用两个其他类(IperfServer和IperfClient),我试图使用多线程来运行它们。我为iperf3使用python包装类。这两个类都启动了,但在运行Iperf时,我得到了分段错误。在Python中使用多线程运行Iperf服务器和客户端导致分段错误
代码片段:
class IperfServer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print("1")
server = iperf3.Server()
print("2")
server.port = 5201
response = server.run()
class IperfClient(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print("3")
connection = http.client.HTTPSConnection("abc.efg")
print("4")
connection.request(method="GET", url="/hij/")
response = connectn.getresponse()
connectn.close()
print("5")
client = iperf3.Client()
client.run()
class IperfAgent(object):
thread1 = IperfClient()
thread2 = IperfServer()
thread1.start()
thread2.start()
OUTPUT:
分段错误
我是一个新手,Python和多线程。有人能帮我弄清楚我犯的错误吗?
答
尝试在子进程中运行它(请参阅multiprocessing.Process)而不是线程。
看来,iperf_defaults需要在主线程上运行。
对于客户端,不应该使用'iperf3.client()'? – Adonis
是的。我在'print(“5”)'语句下面使用了这个。 –
你解决了这个问题吗? – h3ct0r