【发布时间】:2017-08-28 20:51:13
【问题描述】:
这是我正在尝试做的最小版本。这是我的main.py 文件:
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)
...
这是我的 task.py 文件,其中包含 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'))
但永远不会调用 on_success 回调。在urlrequest.py的第439行:
if self.on_success:
func = self.on_success()
if func:
func(self, data)
func 是 None,所以不会调用回调。在尝试访问 self.proxy 时,weakmethod.py 中的第 47 行也会引发 ReferenceError: weakly-referenced object no longer exists。
try:
if self.proxy:
return getattr(self.proxy, self.method_name)
except ReferenceError:
pass
return self.method
这里有什么问题?我的DownloadTask() 对象被垃圾回收了吗?
环境:Python 3.5.3、Kivy 1.10.0、mac os
【问题讨论】:
标签: python callback garbage-collection kivy