From ff9ae0117de4cd1df174753c40d04a72e56d7cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 Jan 2019 11:32:31 +0100 Subject: [PATCH] Fixed race condition referring to self when operator may have stopped running The `file_loading` function is called deferred by asyncio, and can thus be called when the operator has already stopped loading. This is fixed by not referring to `self` in that function, and taking the logger from the outer scope. --- blender_cloud/texture_browser/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/blender_cloud/texture_browser/__init__.py b/blender_cloud/texture_browser/__init__.py index edf18ad..800be5a 100644 --- a/blender_cloud/texture_browser/__init__.py +++ b/blender_cloud/texture_browser/__init__.py @@ -707,18 +707,19 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin, resolution = next(file_ref['resolution'] for file_ref in node['properties']['files'] if file_ref['file'] == file_uuid) - self.log.info('Downloading file %r-%s to %s', file_uuid, resolution, local_path) - self.log.debug('Metadata will be stored at %s', meta_path) + my_log = self.log + my_log.info('Downloading file %r-%s to %s', file_uuid, resolution, local_path) + my_log.debug('Metadata will be stored at %s', meta_path) def file_loading(file_path, file_desc, map_type): - self.log.info('Texture downloading to %s (%s)', - file_path, utils.sizeof_fmt(file_desc['length'])) + my_log.info('Texture downloading to %s (%s)', + file_path, utils.sizeof_fmt(file_desc['length'])) async def file_loaded(file_path, file_desc, map_type): if context.scene.local_texture_dir.startswith('//'): file_path = bpy.path.relpath(file_path) - self.log.info('Texture downloaded to %s', file_path) + my_log.info('Texture downloaded to %s', file_path) current_image['bcloud_file_uuid'] = file_uuid current_image.filepath = file_path # This automatically reloads the image from disk.