最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to always get the status of the robot when using POST request and not make the app crashing - Stack Overflow

programmeradmin4浏览0评论

I created a Windows application in Python and the Kivy framework. The main feature of the app is to post the request on the server in API through a button. The server will send the task to a robot and will respond to my app in JSON format. Depending on the status of the robot, the server will give the data following it, and I will give the feedback to the user in color.

For example, the server response "taskStatus":"4"

I will display the green color, and if the server response number is "6" I will display the orange.

I try using the "thread" and "schedule" modules to test it. But it still makes the app crash. You can see my example code

from threading import Thread
    
   def post_device_status_background():
        api_url_get = "http://*.*.*.*:7000/ics/out/task/getTaskOrderStatus"
        data = {
            "areaId": "1",
            "deviceType": "0",
            "deviceCode": "khang0000"
        }
        try:
            response = requests.post(api_url_get, json=data)
            print("Device status:", response.json())
        except Exception as e:
            print(f"Error: {e}")
    
    def post_device_status(self, dt):
        Thread(target=post_device_status_background).start()
    
    Clock.schedule_interval(post_device_status, 10)

The main point of my question is how to always get the status of the robot after clicking the button and not make the app crash? Do you have any advice?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论