realpython / realpython/materials
Socket with if-loops does not give a consistent result
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Jupyter Notebook
- Star
- 5.2k
- Fork
- 5.3k
- Merge trung bình
- 4 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 10
Mô tả
The program is continuously receiving data from the sender side. And I have a checked/unchecked button when I make it checked it runs the if part...that's good. Now I make it unchecked then else part runs and prints Unchecked going to close socket, so that's also good.
The problem is when I am going to make it again checked (2nd time) to run if part again it just print Checked and my program hangs. Why is this happening? It should receive the data but it hangs. Please tell me the solution.
def show_markers(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostbyname('192.168.225.12')
s.connect((host, port))
scale=0
while True:
if self.iconAction.isChecked():
print ('Checked')
m = QgsVertexMarker(self.iface.mapCanvas())
data = s.recv(SIZE)
data1 = s.recv(SIZE)
c = data.decode()
d = data1.decode()
x = float(c)
y = float(d)
print("printing X :", x)
print("printing Y :", y)
rect = QgsRectangle(float(x)-scale, float(y)-scale, float(x)+scale, float(y)+scale)
me = self.iface.mapCanvas()
me.setExtent(rect)
me.refresh()
m.setCenter(QgsPointXY(x, y))
m.setColor(QColor(255, 0, 0))
m.setIconSize(7)
m.setIconType(QgsVertexMarker.ICON_X) # or ICON_CROSS, ICON_X
m.setPenWidth(3)
else:
print('Unchecked going to close socket')
s.shutdown(10)
s.close()
I am assuming it should work like:
- 1st time click on button ---> Checked & if part run [working]
- 2nd time click on button ---> Unchecked & else part run [working]
- 3rd time click on button ---> again it Checked [here it checked but my program hangs & not receiving the data from sender computer]
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu tại điểm vào show_markers và lần theo vòng lặp xoay quanh trạng thái của checkbox, các lệnh gọi recv và các đường dẫn shutdown/close của socket. Tái hiện chuỗi ba lần chuyển đổi, sau đó xác minh rằng khi quay lại trạng thái đã chọn, dữ liệu được nhận mà không bị treo và vòng đời của socket vẫn hợp lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- desktop, networking
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100