Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python: Running a time-taking process/function in background without freezing UI

3 REPLIES 3
Reply
Message 1 of 4
NemKumar
461 Views, 3 Replies

Python: Running a time-taking process/function in background without freezing UI

Hi,

 

I am working on a python based plugin. I am calling a few functions that send web requests and wait for a response. The problem is, the UI freezes while the function waits for the request to complete. I am uploading geometries and performing some status-checking REST calls continuously. I also wish to show the progress while it's all happening. So, my requirement is:

 

1.) I need to run the time-taking function calls in the background, separate from the main thread, so the UI doesn't freeze.

2.) Update the progress in the progress bar, by tracking the status of the calls. I want to know how I can track what's happening in the separate thread.

 

Can someone please suggest a good solution?

 

Thanks in advance 

3 REPLIES 3
Message 2 of 4
liujac
in reply to: NemKumar

Hi,

 

You may try with progress dialog (UserInterface.createProgressDialog) for time-consuming work, so that you can update the progress and UI doesn’t freeze.

 

Jack

Message 3 of 4
productbakery
in reply to: NemKumar

You can maybe add adsk.doEvents() on strategic places in your code to give Fusion some time to run its own tasks..

Message 4 of 4
Jorge_Jaramillo
in reply to: NemKumar

Hi,

 

You can create a separate thread to run the communication staff without blocking Fusion 360's main thread.

You can read on this link about it.

According to my experience, all design operations need to be done in the main Fusion 360's thread, so, just use the other threads to make not-Fusion calls; otherwise, Fusion 360 could crash.

Also notice that you can use asynchronous calling methods to send requests and wait for the responses.  Here you have some Python docs about it: https://docs.python.org/3/library/asyncio.html

 

Regards,

Jorge Jaramillo

Software Engineer

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report