Is there any way to cancel UrlRequest in Kivy?
<p>Is there any way to cancel UrlRequest in Kivy?</p>

<pre><code>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
</code></pre>

<p>This is just example: I know about timeout, I want to cancel request on some arbitrary event. </p>

<p>Afaik there's no other way except <code>UrlRequest.timeout</code>, which could translate to politely wait and close any harmful stuff safely. It uses <code>Thread</code> which may and may not be dangerous. Even more if e.g. packaged into exe or other form of binary where it could create a lock because something broke. I think the way you would like it to use would only trigger problems.</p>

<p>There's another way using <code>on_*</code> events and as small as possible <code>timeout</code>, which can trigger your function.</p>

<p>Example: set timeout for 1s if you want to cancel it after that amount of time and let the UrlRequest ping you when it does so, which is</p>

<ol>
<li>safer to use than stopping it at random place</li>
<li>less amount of lines for reinventing the wheel</li>
</ol>

python kivy