| 534 | return examples_to_test, examples_nocode |
| 535 | |
| 536 | def _execute_xdoctest( |
| 537 | self, examples_to_test, examples_nocode, **directives |
| 538 | ): |
| 539 | # if use solo(single process), execute without multiprocessing/thread |
| 540 | if directives.get('solo') is not None: |
| 541 | return self._execute(examples_to_test, examples_nocode) |
| 542 | |
| 543 | if self._use_multiprocessing: |
| 544 | _ctx = multiprocessing.get_context('spawn') |
| 545 | result_queue = _ctx.Queue() |
| 546 | exec_processor = functools.partial(_ctx.Process, daemon=True) |
| 547 | else: |
| 548 | result_queue = queue.Queue() |
| 549 | exec_processor = functools.partial(threading.Thread, daemon=True) |
| 550 | |
| 551 | processor = exec_processor( |
| 552 | target=self._execute_with_queue, |
| 553 | args=( |
| 554 | result_queue, |
| 555 | examples_to_test, |
| 556 | examples_nocode, |
| 557 | ), |
| 558 | ) |
| 559 | |
| 560 | processor.start() |
| 561 | result = result_queue.get( |
| 562 | timeout=directives.get('timeout', TEST_TIMEOUT) |
| 563 | ) |
| 564 | processor.join() |
| 565 | |
| 566 | return result |
| 567 | |
| 568 | def _execute(self, examples_to_test, examples_nocode): |
| 569 | """Run xdoctest for each example""" |