gpt4 book ai didi

python - 使用 Pyside 时文件描述符错误

转载 作者:太空狗 更新时间:2023-10-30 01:33:56 25 4
gpt4 key购买 nike

我的代码:

class Receiver(QWidget):
def __init__(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Create button
QToolTip.setFont(QFont('Time New Roman',10))
super(Example, self).__init__()
...
self.btnConnect.clicked.connect(self.connectserver)
self.btnConnect.clicked.connect(self.disconnect)
self.btnLeft.clicked.connect(self.turnleft)
self.btnRight.clicked.connect(self.turnright)
def connectserver(self):
self.s.connect((TCP_IP, TCP_PORT))
length = recvall(conn,16)
stringData = recvall(s, int(length))
while True:
data = numpy.fromstring(stringData, dtype='uint8')
decimg=cv2.imdecode(data,1)
cv2.imshow('Client',decimg)
cv2.waitKey(10)
def disconnect(self):
self.s.close()
def turnleft(self):
self.s.send("left")
def turnright(self):
self.s.send("right")

首先,我单击“连接”按钮。它工作正常,但是当我单击“向左转”或“向右转”时,出现错误:

Traceback (most recent call last):
File "D:\NEW\GUI.py", line 69, in turnright
self.s.send("right")
File "C:\Python27\lib\socket.py", line 170, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor

最佳答案

您已将 btnConnect 连接到 connectserverdisconnect,因此当您单击它时,它将连接然后立即断开套接字。

如果您尝试将数据发送到已关闭的套接字,则会引发错误的文件描述符错误。

关于python - 使用 Pyside 时文件描述符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27488930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com