Open cmeyer opened 6 months ago
@cmeyer just looking at this one - I think it might make sense to split this one in half Chris. One part for moving the exporting on to a thread (not sure about the architecture needs on that but that's a dev question/problem), the other part to hook up a progress bar for it. Is that OK with you?
@jamesrussell216 What about changing #749 to be the 'dialog + progress bar' and leaving this as the threading issue. They're probably going to need to be implemented at the same time, but #749 might be a good spot to fill out the details of the dialog. I'm thinking something like the 'downloads' progress list in a browser, except for exporting.
@cmeyer I'd leave #749 be as that's more specific to an export bug. I'll make a new issue for the progress bar and link it in here. And then yes let's make this one specific to moving exports off the main thread. Yes they do make sense to do at the same time, but they are separate - arguably moving the exports on to a separate thread could be done (and released) without a progress bar is really needed, it would still be a step forward over the current situation I'd say. But equally yes it does really make sense to do both at the same time when we're "in the area" so to speak.
After expanding #1053 I decided that this one stands as the "export in a thread" issue. Adjusted title slightly and made #1053 dependent on this.
@cmeyer you mentioned in chat you had some thoughts about the potential best route to implement this - can you drop a reference of some form in here for us plz?
I can write up a more thorough explanation, but quickly: the periodic
function executes on the UI thread every 50ms and runs pending async
functions. Those async
functions usually suspend themselves quickly (~10ms), letting other UI-level functions run. One of the ways they can suspend themselves is by running another function in a thread via the run_in_executor
function and then await
ing that function. We should run the export thread via this mechanism.
An example of this is here:
You can trace through the calls to get_value_and_position_text_async
to see how it gets called from periodic
.
We'll also need to design a mechanism for handling shutdown, cancellation, and other similar situations. We may want to discuss implementation plans in more detail before starting. There are a lot of pitfalls to this project.
@cmeyer worth getting it on the agenda for tomorrow's software call?
Currently the export code resides in the export_clicked
method in ExportDialog.py
. It should be moved to reside in the ExportAction.execute
method. It is ok for the execute
method to extract the necessary parameters from the action context and then call a method in DocumentModel
or standalone function or just put the code in ExportAction.execute
. This is a useful refactoring to prepare for implementing threaded export.
Users often want to export to continue processing on another computer, but also continue doing acquisition while exporting.