| 45 | |
| 46 | |
| 47 | class _WorkItem: |
| 48 | def __init__(self, future, fn, args, kwargs): |
| 49 | self.future = future |
| 50 | self.fn = fn |
| 51 | self.args = args |
| 52 | self.kwargs = kwargs |
| 53 | |
| 54 | def run(self): |
| 55 | if not self.future.set_running_or_notify_cancel(): |
| 56 | return |
| 57 | |
| 58 | try: |
| 59 | result = self.fn(*self.args, **self.kwargs) |
| 60 | except BaseException as exc: |
| 61 | self.future.set_exception(exc) |
| 62 | # Break a reference cycle with the exception 'exc' |
| 63 | self = None |
| 64 | else: |
| 65 | self.future.set_result(result) |
| 66 | |
| 67 | __class_getitem__ = classmethod(types.GenericAlias) |
| 68 | |
| 69 | |
| 70 | def _worker(executor_reference, work_queue, initializer, initargs): |