Я создаю файл сценария для использования в fusion 360, и когда я пытаюсь выполнить асинхронную функцию, обязательно возникают некоторые или другие ошибки.
Ниже приведена более простая версия одной из моих проблем:
`Failed:
Traceback (most recent call last):
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 166, in assert_mta
await event.wait()
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\locks.py", line 212, in wait
await fut
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 165, in assert_mta
async with async_timeout(0.5):
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\timeouts.py", line 115, in __aexit__
raise TimeoutError from exc_val
TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 37, in notify
auto_rotate_camera()
File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 28, in auto_rotate_camera
asyncio.run(fu())
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 21, in fu
l = await bleak.BleakScanner.discover()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\__init__.py", line 320, in discover
async with cls(**kwargs) as scanner:
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\__init__.py", line 158, in __aenter__
await self._backend.start()
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\scanner.py", line 225, in start
await assert_mta()
File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 168, in assert_mta
raise BleakError(
bleak.exc.BleakError: Thread is configured for Windows GUI but callbacks are not working.
`
Код asyncio правильно работает автономно, если он не запускается в файле сценария Fusion.
Я создаю файл сценария для использования в fusion 360, и когда я пытаюсь выполнить асинхронную функцию, обязательно возникают некоторые или другие ошибки. Ниже приведена более простая версия одной из моих проблем: [code]` # import Client.Client import adsk.core, adsk.fusion, traceback import asyncio import math import bleak
# Command properties commandId = 'SetCameraAutoRotateCommand' commandName = 'Auto Rotate Camera' commandDescription = 'Automatically rotate the camera around all angles.'
app = adsk.core.Application.get() ui = app.userInterface if app else None
# Global handlers to maintain references eventHandlers = []
async def fu(): l = await bleak.BleakScanner.discover() ui.messageBox("List of Devices: ") s=repr(l) # ui.messageBox("List of Devices: ") ui.messageBox(s)
def auto_rotate_camera(): asyncio.run(fu())
# Command event handlers class AutoRotateCommandExecuteHandler(adsk.core.CommandEventHandler): def init(self): super().init()
def notify(self, args): try: auto_rotate_camera() except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class AutoRotateCommandDestroyHandler(adsk.core.CommandEventHandler): def init(self): super().init()
def notify(self, args): try: adsk.terminate() except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class AutoRotateCommandCreatedHandler(adsk.core.CommandCreatedEventHandler): def init(self): super().init()
except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))` [/code] Вот сообщение об ошибке [code]`bleak.exc.BleakError: Thread is configured for Windows GUI but callbacks are not working.` [/code] Вот полный журнал ошибок: [code]`Failed: Traceback (most recent call last): File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 166, in assert_mta await event.wait() File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\locks.py", line 212, in wait await fut asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 165, in assert_mta async with async_timeout(0.5): File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\timeouts.py", line 115, in __aexit__ raise TimeoutError from exc_val TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 37, in notify auto_rotate_camera() File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 28, in auto_rotate_camera asyncio.run(fu()) File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:/Users/HOST_USER/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/file1/file1.py", line 21, in fu l = await bleak.BleakScanner.discover() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\__init__.py", line 320, in discover async with cls(**kwargs) as scanner: File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\__init__.py", line 158, in __aenter__ await self._backend.start() File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\scanner.py", line 225, in start await assert_mta() File "C:\Users\HOST_USER\AppData\Local\Autodesk\webdeploy\production\bce2902bbfcb27678033cbb9e17a3529631b97a7\Python\lib\site-packages\bleak\backends\winrt\util.py", line 168, in assert_mta raise BleakError( bleak.exc.BleakError: Thread is configured for Windows GUI but callbacks are not working. ` [/code] Код asyncio правильно работает автономно, если он не запускается в файле сценария Fusion.