| 70 | |
| 71 | |
| 72 | class TransferFuture(BaseTransferFuture): |
| 73 | def __init__(self, meta=None, coordinator=None): |
| 74 | """The future associated to a submitted transfer request |
| 75 | |
| 76 | :type meta: TransferMeta |
| 77 | :param meta: The metadata associated to the request. This object |
| 78 | is visible to the requester. |
| 79 | |
| 80 | :type coordinator: TransferCoordinator |
| 81 | :param coordinator: The coordinator associated to the request. This |
| 82 | object is not visible to the requester. |
| 83 | """ |
| 84 | self._meta = meta |
| 85 | if meta is None: |
| 86 | self._meta = TransferMeta() |
| 87 | |
| 88 | self._coordinator = coordinator |
| 89 | if coordinator is None: |
| 90 | self._coordinator = TransferCoordinator() |
| 91 | |
| 92 | @property |
| 93 | def meta(self): |
| 94 | return self._meta |
| 95 | |
| 96 | def done(self): |
| 97 | return self._coordinator.done() |
| 98 | |
| 99 | def result(self): |
| 100 | try: |
| 101 | # Usually the result() method blocks until the transfer is done, |
| 102 | # however if a KeyboardInterrupt is raised we want want to exit |
| 103 | # out of this and propagate the exception. |
| 104 | return self._coordinator.result() |
| 105 | except KeyboardInterrupt as e: |
| 106 | self.cancel() |
| 107 | raise e |
| 108 | |
| 109 | def cancel(self): |
| 110 | self._coordinator.cancel() |
| 111 | |
| 112 | def set_exception(self, exception): |
| 113 | """Sets the exception on the future.""" |
| 114 | if not self.done(): |
| 115 | raise TransferNotDoneError( |
| 116 | 'set_exception can only be called once the transfer is ' |
| 117 | 'complete.' |
| 118 | ) |
| 119 | self._coordinator.set_exception(exception, override=True) |
| 120 | |
| 121 | |
| 122 | class TransferMeta(BaseTransferMeta): |
no outgoing calls