Poll the server for the status of a set of problems. Note: This method is always run inside of a daemon thread.
(self)
| 1639 | self._poll_queue.put((created_at, future)) |
| 1640 | |
| 1641 | def _do_poll_problems(self): |
| 1642 | """Poll the server for the status of a set of problems. |
| 1643 | |
| 1644 | Note: |
| 1645 | This method is always run inside of a daemon thread. |
| 1646 | """ |
| 1647 | session = self.create_session() |
| 1648 | session.set_accept(media_type='application/vnd.dwave.sapi.problems+json', |
| 1649 | accept_version='~=3.0', ask_version='3.0.0') |
| 1650 | try: |
| 1651 | # grouped futures (all scheduled within _POLL_GROUP_TIMEFRAME) |
| 1652 | # and/or up to _STATUS_QUERY_SIZE (depending on strategy) |
| 1653 | frame_futures = {} |
| 1654 | |
| 1655 | use_long_polling = ( |
| 1656 | self.config.polling_schedule.strategy == PollingStrategy.LONG_POLLING) |
| 1657 | |
| 1658 | def task_done(): |
| 1659 | self._poll_queue.task_done() |
| 1660 | |
| 1661 | def add(future): |
| 1662 | # add future to query frame_futures |
| 1663 | # returns: worker lives on? |
| 1664 | |
| 1665 | # `None` task signifies thread termination |
| 1666 | if future is None: |
| 1667 | task_done() |
| 1668 | return False |
| 1669 | |
| 1670 | if future.id not in frame_futures and not future.done(): |
| 1671 | frame_futures[future.id] = future |
| 1672 | else: |
| 1673 | task_done() |
| 1674 | |
| 1675 | return True |
| 1676 | |
| 1677 | while True: |
| 1678 | frame_futures.clear() |
| 1679 | |
| 1680 | # blocking add first scheduled |
| 1681 | frame_earliest, future = self._poll_queue.get() |
| 1682 | if not add(future): |
| 1683 | return |
| 1684 | |
| 1685 | # try grouping if scheduled within grouping timeframe |
| 1686 | # (or in the long polling case, add up to _STATUS_QUERY_SIZE available futures) |
| 1687 | while len(frame_futures) < self._STATUS_QUERY_SIZE: |
| 1688 | try: |
| 1689 | task = self._poll_queue.get_nowait() |
| 1690 | except queue.Empty: |
| 1691 | break |
| 1692 | |
| 1693 | at, future = task |
| 1694 | if use_long_polling or (at - frame_earliest <= self._POLL_GROUP_TIMEFRAME): |
| 1695 | if not add(future): |
| 1696 | return |
| 1697 | else: |
| 1698 | self._poll_queue.put(task) |
nothing calls this directly
no test coverage detected