|
9 | 9 | from datetime import datetime |
10 | 10 | import time |
11 | 11 | from copy import deepcopy |
| 12 | +import asyncio |
12 | 13 |
|
13 | 14 | import numpy as np |
14 | 15 | import pandas as pd |
|
25 | 26 | COMPUTE_BACKENDS, |
26 | 27 | COMPUTE_BACKEND_SUBPROCESS, |
27 | 28 | COMPUTE_BACKEND_LOCAL, |
| 29 | + COMPUTE_BACKEND_ASYNC, |
28 | 30 | get_parent_raw_data_path, |
29 | 31 | load_batch, |
30 | 32 | ) |
@@ -531,19 +533,30 @@ def __init__(self, s: pd.Series): |
531 | 533 | self.process: Popen = None |
532 | 534 |
|
533 | 535 | def _run_local( |
534 | | - self, |
535 | | - algo: str, |
536 | | - batch_path: Path, |
537 | | - uuid: UUID, |
538 | | - data_path: Union[Path, None], |
539 | | - ): |
| 536 | + self, |
| 537 | + algo: str, |
| 538 | + batch_path: Path, |
| 539 | + uuid: UUID, |
| 540 | + data_path: Union[Path, None], |
| 541 | + dview=None |
| 542 | + ) -> DummyProcess: |
| 543 | + coroutine = self._run_local_async(algo, batch_path, uuid, data_path, dview) |
| 544 | + asyncio.run(coroutine) |
| 545 | + return DummyProcess() |
| 546 | + |
| 547 | + def _run_local_async( |
| 548 | + self, |
| 549 | + algo: str, |
| 550 | + batch_path: Path, |
| 551 | + uuid: UUID, |
| 552 | + data_path: Union[Path, None], |
| 553 | + dview=None |
| 554 | + ) -> Coroutine: |
540 | 555 | algo_module = getattr(algorithms, algo) |
541 | | - algo_module.run_algo( |
542 | | - batch_path=str(batch_path), uuid=str(uuid), data_path=str(data_path) |
| 556 | + return algo_module.run_algo_async( |
| 557 | + batch_path=str(batch_path), uuid=str(uuid), data_path=str(data_path), dview=dview |
543 | 558 | ) |
544 | 559 |
|
545 | | - return DummyProcess() |
546 | | - |
547 | 560 | def _run_subprocess(self, runfile_path: str, wait: bool, **kwargs): |
548 | 561 |
|
549 | 562 | # Get the dir that contains the input movie |
@@ -636,13 +649,14 @@ def run(self, backend: Optional[str] = None, wait: bool = True, **kwargs): |
636 | 649 |
|
637 | 650 | batch_path = self._series.paths.get_batch_path() |
638 | 651 |
|
639 | | - if backend == COMPUTE_BACKEND_LOCAL: |
640 | | - print(f"Running {self._series.uuid} with local backend") |
641 | | - return self._run_local( |
| 652 | + if backend in [COMPUTE_BACKEND_LOCAL, COMPUTE_BACKEND_ASYNC]: |
| 653 | + print(f"Running {self._series.uuid} with {backend} backend") |
| 654 | + return getattr(self, f"_run_{backend}")( |
642 | 655 | algo=self._series["algo"], |
643 | 656 | batch_path=batch_path, |
644 | 657 | uuid=self._series["uuid"], |
645 | 658 | data_path=get_parent_raw_data_path(), |
| 659 | + dview=kwargs.get("dview") |
646 | 660 | ) |
647 | 661 |
|
648 | 662 | # Create the runfile in the batch dir using this Series' UUID as the filename |
|
0 commit comments