Submit a task to complete :type task: s3transfer.tasks.Task :param task: The task to run __call__ on :type tag: s3transfer.futures.TaskTag :param tag: An optional tag to associate to the task. This is used to override which semaphore to use. :t
(self, task, tag=None, block=True)
| 462 | self._tag_semaphores = tag_semaphores |
| 463 | |
| 464 | def submit(self, task, tag=None, block=True): |
| 465 | """Submit a task to complete |
| 466 | |
| 467 | :type task: s3transfer.tasks.Task |
| 468 | :param task: The task to run __call__ on |
| 469 | |
| 470 | |
| 471 | :type tag: s3transfer.futures.TaskTag |
| 472 | :param tag: An optional tag to associate to the task. This |
| 473 | is used to override which semaphore to use. |
| 474 | |
| 475 | :type block: boolean |
| 476 | :param block: True if to wait till it is possible to submit a task. |
| 477 | False, if not to wait and raise an error if not able to submit |
| 478 | a task. |
| 479 | |
| 480 | :returns: The future associated to the submitted task |
| 481 | """ |
| 482 | semaphore = self._semaphore |
| 483 | # If a tag was provided, use the semaphore associated to that |
| 484 | # tag. |
| 485 | if tag: |
| 486 | semaphore = self._tag_semaphores[tag] |
| 487 | |
| 488 | # Call acquire on the semaphore. |
| 489 | acquire_token = semaphore.acquire(task.transfer_id, block) |
| 490 | # Create a callback to invoke when task is done in order to call |
| 491 | # release on the semaphore. |
| 492 | release_callback = FunctionContainer( |
| 493 | semaphore.release, task.transfer_id, acquire_token |
| 494 | ) |
| 495 | # Submit the task to the underlying executor. |
| 496 | # Pass the current context to ensure child threads persist the |
| 497 | # parent thread's context. |
| 498 | future = ExecutorFuture(self._executor.submit(task, get_context())) |
| 499 | # Add the Semaphore.release() callback to the future such that |
| 500 | # it is invoked once the future completes. |
| 501 | future.add_done_callback(release_callback) |
| 502 | return future |
| 503 | |
| 504 | def shutdown(self, wait=True): |
| 505 | self._executor.shutdown(wait) |