python - Kivy UrlRequest doesn't trigger callback -


this minimal version of i'm trying do. main.py file:

class mainscreen(screen):     def __init__(self):         super(mainscreen, self).__init__()         self.url_input = textinput()         self.start = button(text='download')          self.start.bind(on_release=partial(self.on_start_press))         self.add_widget(self.url_input)         self.add_widget(self.start)      def on_start_press(self, *args):         downloadtask(self.url_input.text)         ... 

and task.py file contains downloadtask.

class downloadtask(object):     def __init__(self, url):         self.url = url         self._get_headers()      def _get_headers(self):         urlrequest(url=self.url, on_success=self._on_headers_fetched, method='head')      def _on_headers_fetched(self, req, resp):         self.content_length = int(req.resp_headers.get('content-length')) 

but on_success callback never called. on line 439 of urlrequest.py:

if self.on_success:     func = self.on_success()         if func:             func(self, data) 

func none no callback called. line 47 in weakmethod.py raises referenceerror: weakly-referenced object no longer exists when trying access self.proxy.

try:     if self.proxy:         return getattr(self.proxy, self.method_name) except referenceerror:     pass return self.method 

what issue here? downloadtask() object garbage collected?

environemnt: python 3.5.3, kivy 1.10.0, mac os

edit: after source revealed, appears me downloadtask object garbage-collected, therefore thread ran urlrequest called weakproxy method of object doesn't exist - therefore crash.


whether garbage-collected or not i'm not sure, request creates daemon thread, therefore shouldn't care (feel free find out). there's comment it, isn't collected yet.

the urlrequest depends on kivy , that's visible here. uses kivy clock. means unless kivy application run, request won't proceed further i.e. should stop on line. try add print('something') urlrequest._dispatch_result() , you'll see it's ignored, because kivy clock isn't ticking (therefore function isn't called).

however example, actual kivy application run don't see problem it.

from kivy.app import runtouchapp kivy.uix.widget import widget kivy.network.urlrequest import urlrequest  class my(widget):     def __init__(self, **kwargs):         super(my, self).__init__(**kwargs)         urlrequest(             url='http://lipsum.com/',             on_error=lambda *args: print('error:', args),             on_failure=lambda *args: print('fail:', args),             on_redirect=lambda *args: print('redir:', args),             on_success=lambda *args: print('success:', args)         )  runtouchapp(my()) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -