I amI'm new to Blender pythonPython programming, and for a personal project am playing around, I'm experimenting with creating a Blender pythonPython addon where. I can doaim to execute an async getasynchronous GET request when I select a button in a panel (custom operator). SeeYou can find an example code snippet below. My current issue is that when I selectupon selecting the operator, it seemsappears to be blockingblock any other Blender interactions until the asyncasynchronous call has finished runningcompletes. AnyDo you have any suggestions/examples for or examples on how I can haveprevent the operatoroperator's logic not blockfrom blocking? I’dI still like the userwant users to be able to continue with editing their models, etc., while these apiAPI calls/downloads happenoccur.
import bpy
import json
import asyncio
import aiohttp
from bpy.types import Operator, Panel
# ------------------------------------------------------------------------
# Operators
# ------------------------------------------------------------------------
class ADDON_OT_test(Operator):
bl_idname = "addon.search"
bl_label = "Search"
def execute(self, context):
scene = context.scene
mytool = scene.my_properties
# Endpoint Resource Path
assets_url = "someurl"
# Request Body
assets_query_body = { }
# Request Headers
headers = { }
x = asyncio.run(fetch_data(assets_url, assets_query_body, headers))
if x is None:
self.report({'ERROR'}, "something went wrong")
else:
beautify_data = json.dumps(x, indent=4)
print(beautify_data)
self.report({'INFO'}, "all done")
return {'FINISHED'}
# ------------------------------------------------------------------------
# Panels
# ------------------------------------------------------------------------
class ADDON_PT_browse_search_panel(Panel):
bl_idname = "ADDON_PT_Search_Results"
bl_label = "Search Results"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw (self, context):
layout = self.layout
scene = context.scene
mytool = scene.my_properties
layout.operator("addon.search", text="Search")
# ------------------------------------------------------------------------
# Additional Functionality
# ------------------------------------------------------------------------
async def fetch_data(url, query_params=None, headers=None):
async with aiohttp.ClientSession() as session:
async with session.get(url, params=query_params, headers=headers) as response:
print("Status:", response.status)
if response.status == 200:
print(response.status)
return await response.json()
else:
print(response.status)
return None
# ------------------------------------------------------------------------
# Register/Deregister
# ------------------------------------------------------------------------
classes = [
ADDON_PT_browse_search_panel,
ADDON_OT_test
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
```