Run function `func` in a background thread. Send the signal `self.computations_complete` once computation is finished. Parameters ---------- func: function Reference to a function that is supposed to be executed at the background. The
(self, func, slot, *args, **kwargs)
| 600 | self._recover_after_compute(self.slot_preview_items_changed) |
| 601 | |
| 602 | def _compute_in_background(self, func, slot, *args, **kwargs): |
| 603 | """ |
| 604 | Run function `func` in a background thread. Send the signal |
| 605 | `self.computations_complete` once computation is finished. |
| 606 | |
| 607 | Parameters |
| 608 | ---------- |
| 609 | func: function |
| 610 | Reference to a function that is supposed to be executed at the background. |
| 611 | The function return value is passed as a signal parameter once computation is |
| 612 | complete. |
| 613 | slot: qtpy.QtCore.Slot or None |
| 614 | Reference to a slot. If not None, then the signal `self.computation_complete` |
| 615 | is connected to this slot. |
| 616 | args, kwargs |
| 617 | arguments of the function `func`. |
| 618 | """ |
| 619 | signal_complete = self.computations_complete |
| 620 | |
| 621 | def func_to_run(func, *args, **kwargs): |
| 622 | class LoadFile(QRunnable): |
| 623 | def run(self): |
| 624 | result_dict = func(*args, **kwargs) |
| 625 | signal_complete.emit(result_dict) |
| 626 | |
| 627 | return LoadFile() |
| 628 | |
| 629 | if slot is not None: |
| 630 | self.computations_complete.connect(slot) |
| 631 | self.gui_vars["gui_state"]["running_computations"] = True |
| 632 | self.update_global_state.emit() |
| 633 | QThreadPool.globalInstance().start(func_to_run(func, *args, **kwargs)) |
| 634 | |
| 635 | def _recover_after_compute(self, slot): |
| 636 | """ |
no test coverage detected