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

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

NemKumar
Enthusiast Enthusiast
756 Views
3 Replies
Message 1 of 4

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

NemKumar
Enthusiast
Enthusiast

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 

0 Likes
757 Views
3 Replies
Replies (3)
Message 2 of 4

liujac
Alumni
Alumni

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

0 Likes
Message 3 of 4

productbakery
Participant
Participant

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

0 Likes
Message 4 of 4

Jorge_Jaramillo
Collaborator
Collaborator

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

 

0 Likes