Python 有没有办法取消Kivy中的URL请求?

Python 有没有办法取消Kivy中的URL请求?,python,kivy,Python,Kivy,有没有办法取消Kivy中的URL请求 def got_url(req, result): print(result) req = UrlRequest('http://httpbin.org/delay/2', got_url) # Request lasts 2 seconds def my_callback(dt): print('Request cancelled.') # sort of req.cancel() Clock.schedule_once(my_

有没有办法取消Kivy中的URL请求

def got_url(req, result):
    print(result)
req = UrlRequest('http://httpbin.org/delay/2', got_url)  # Request lasts 2 seconds

def my_callback(dt):
    print('Request cancelled.')
    # sort of req.cancel()
Clock.schedule_once(my_callback, 1)  # But some event happens after 1 sec. and I want to cancel request

这只是一个例子:我知道超时,我想取消一些任意事件的请求

Afaik除了
UrlRequest.timeout
,没有其他方法,它可以转换为礼貌地等待并安全地关闭任何有害的东西。它使用
线程
,这可能会也可能不会有危险。如果将其打包成exe或其他形式的二进制文件,则可能会因为某个东西坏了而创建锁。我认为你希望它使用的方式只会引发问题

还有另一种方法是在事件上使用
,并且尽可能小的
超时时间
,这可以触发您的函数

示例:如果要在该时间段后取消超时,请将超时设置为1s,并在URL请求执行此操作时让其ping您,这是

  • 使用起来比随意停车更安全
  • 减少改造车轮的线路数量