Python 2.7은 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
태스크가 큐에 있으면 작업자는 lease_tasks() 메서드를 사용하여 큐에서 태스크를 한 개 이상 임대할 수 있습니다. add()를 사용하여 최근에 추가된 태스크가 lease_tasks()를 통해 제공되기까지 약간의 지연이 있을 수 있습니다.
임대 요청 시 임대할 작업 수(최대 1,000개 작업)와 임대 기간(초 단위, 최대 1주)을 지정합니다. 임대 기간이 만료되기 전에 가장 느린 태스크를 마칠 수 있을 만큼 임대 기간이 길어야 합니다. modify_task_lease()를 사용하여 태스크 임대를 수정할 수 있습니다.
태스크를 임대하면 다른 작업자가 이 태스크를 처리할 수 없으며 임대가 만료될 때까지 계속 사용할 수 없습니다.
여러 태스크를 서로 구분하기 위해 코드에서 태스크에 '태그'를 지정한 후 태그를 사용하여 임대할 태스크를 선택할 수 있습니다. 태그는 필터의 역할을 합니다.
fromgoogle.appengine.apiimporttaskqueueq=taskqueue.Queue('pull-queue')q.add(taskqueue.Task(payload='parse1',method='PULL',tag='parse'))q.add(taskqueue.Task(payload='parse2',method='PULL',tag='parse'))q.add(taskqueue.Task(payload='render1',method='PULL',tag='render'))q.add(taskqueue.Task(payload='render2',method='PULL',tag='render'))q.lease_tasks_by_tag(3600,100,'render')# leases render tasks, but not parseq.lease_tasks_by_tag(3600,100)# Leases up to 100 tasks that have same tag.
폴링 속도 조절
임대할 태스크의 큐를 폴링하는 작업자는 큐가 공급할 수 있는 것보다 더 빠르게 태스크를 임대하려 하는지 감지해야 합니다. 이러한 오류가 발생하면 lease_tasks()에서 다음과 같은 예외가 발생할 수 있습니다.
코드는 이러한 예외를 포착하여 lease_tasks() 호출을 보류한 후 나중에 다시 시도해야 합니다. 이 문제를 방지하려면 lease_tasks()를 호출할 때 더 높은 RPC 기한을 설정하는 것이 좋습니다. 또한 임대 요청이 빈 태스크 목록을 반환하는 경우에도 보류해야 합니다.
큐별로 초당 LeaseTasks 요청을 10개 넘게 생성하면 처음 10개의 요청만 결과를 반환합니다. 요청이 이 한도를 초과하면 결과 없이 OK가 반환됩니다.
Google Cloud 콘솔에서 태스크 모니터링
애플리케이션의 모든 태스크와 큐에 대한 정보를 확인하는 방법은 다음과 같습니다.
Google Cloud 콘솔에서 Cloud Tasks 페이지를 열고 유형 열에서 Pull 값을 찾습니다.
원하는 큐 이름을 클릭하여 큐 세부정보 페이지를 엽니다. 선택한 큐의 모든 태스크가 표시됩니다.
작업 삭제
작업자는 태스크를 완료한 후 큐에서 해당 태스크를 삭제해야 합니다. 작업자가 작업을 처리한 후에도 대기열에 작업이 남아 있다면 작업자가 실패했을 가능성이 높습니다. 이러한 경우 다른 작업자가 해당 작업을 처리합니다.
lease_task()에서 반환된 것과 같은 태스크 목록을 delete_tasks()에 전달하여 삭제할 수 있습니다.
fromgoogle.appengine.apiimporttaskqueueq=taskqueue.Queue('pull-queue')tasks=q.lease_tasks(3600,100)# Perform some work with the tasks hereq.delete_tasks(tasks)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eWorkers can lease tasks from a pull queue using the \u003ccode\u003elease_tasks()\u003c/code\u003e method, making them unavailable to other workers until the lease expires, with a maximum of 1,000 tasks and a one-week lease duration.\u003c/p\u003e\n"],["\u003cp\u003eTasks can be tagged, allowing workers to lease tasks by specific tags using the \u003ccode\u003elease_tasks_by_tag()\u003c/code\u003e method, enabling the filtering of tasks.\u003c/p\u003e\n"],["\u003cp\u003eWorkers must delete tasks from the queue after processing them using \u003ccode\u003edelete_tasks()\u003c/code\u003e, to ensure that tasks that have been processed are not considered further for work.\u003c/p\u003e\n"],["\u003cp\u003eWorkers polling the queue must handle \u003ccode\u003eTransientError\u003c/code\u003e or \u003ccode\u003eDeadlineExceededError\u003c/code\u003e exceptions and implement a back-off strategy when these occur or when lease requests return an empty list of tasks, this applies also when there are more than 10 LeaseTasks requests per queue per second.\u003c/p\u003e\n"],["\u003cp\u003eThe Cloud Tasks page in the Google Cloud console provides monitoring capabilities for all tasks and queues, allowing users to view details and status of the tasks.\u003c/p\u003e\n"]]],[],null,["# Leasing Pull Tasks\n\nOnce tasks are in a pull queue, a worker can lease them. After the tasks are processed\nthe worker must delete them.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nBefore you begin\n----------------\n\n- Create a [pull queue](/appengine/docs/legacy/standard/python/taskqueue/pull/creating-pull-queues).\n- [Create tasks](/appengine/docs/legacy/standard/python/taskqueue/pull/creating-tasks) and add them to the pull queue.\n\nImportant context\n-----------------\n\n- This method is only applicable to workers that are running within a service in the standard environment.\n- When you use pull queues, you are responsible for scaling your workers based on your processing volume.\n\nLeasing tasks\n-------------\n\nAfter the tasks are in the queue, a worker can lease one or more of them using the [`lease_tasks()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Queue.lease_tasks) method. There may be a short delay before tasks recently added using [`add()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Queue.add) become available via [`lease_tasks()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Queue.lease_tasks).\n\nWhen you request a lease, you specify the number of tasks to lease (up to a maximum of 1,000 tasks) and the duration of the lease in seconds (up to a maximum of one week). The lease duration needs to be long enough to ensure that the slowest task will have time to finish before the lease period expires. You can modify a task lease using [`modify_task_lease()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Queue.modify_task_lease).\n\nLeasing a task makes it unavailable for processing by another worker, and it remains unavailable until the lease expires.\n\nThe [`lease_tasks()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Queue.lease_tasks) method returns a [Task](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue#google.appengine.api.taskqueue.Task) object containing a list of tasks leased from the queue.\n| **Note:** `lease_tasks()` operates only on pull queues. If you attempt to lease tasks added in a push queue, App Engine throws an exception.\nThe following code sample leases 100 tasks from the queue `pull-queue` for one hour:\n\n\u003cbr /\u003e\n\n from google.appengine.api import taskqueue\n\n q = taskqueue.Queue('pull-queue')\n q.lease_tasks(3600, 100)\n\n### Batching with task tags\n\n|\n| **Beta**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nNot all tasks are alike; your code can \"tag\" tasks and then choose tasks to lease by tag. The tag acts as a filter. \n\n from google.appengine.api import taskqueue\n\n q = taskqueue.Queue('pull-queue')\n q.add(taskqueue.Task(payload='parse1', method='PULL', tag='parse'))\n q.add(taskqueue.Task(payload='parse2', method='PULL', tag='parse'))\n q.add(taskqueue.Task(payload='render1', method='PULL', tag='render'))\n q.add(taskqueue.Task(payload='render2', method='PULL', tag='render'))\n\n q.lease_tasks_by_tag(3600, 100, 'render') # leases render tasks, but not parse\n\n q.lease_tasks_by_tag(3600, 100) # Leases up to 100 tasks that have same tag.\n\n### Regulating polling rates\n\nWorkers that poll the queue for tasks to lease should detect whether they are attempting to lease tasks faster than the queue can supply them. If this failure occurs, the following exceptions from `lease_tasks()` can be generated:\n\n- `google.appengine.api.taskqueue.TransientError`\n- `google.appengine.runtime.apiproxy_errors.DeadlineExceededError`\n\n\u003cbr /\u003e\n\nYour code must catch these exceptions, back off from calling `lease_tasks()`, and then try again later. To avoid this problem, consider setting a higher RPC deadline when calling [lease_tasks()](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue.taskqueue#google.appengine.api.taskqueue.taskqueue.Queue.lease_tasks). You should also back off when a lease request returns an empty list of tasks. \n\nIf you generate more than 10 LeaseTasks requests per queue per second, only the first 10 requests will return results. If requests exceed this limit, `OK` is returned with zero results.\n\n\nMonitoring tasks in the Google Cloud console\n--------------------------------------------\n\nTo view information about all the tasks and queues in your application:\n\n1. Open the **Cloud Tasks** page in the Google Cloud console and look for the *Pull* value in column **Type**.\n\n [Go to Cloud Tasks](https://console.cloud.google.com/cloudtasks)\n2. Click on the name of the queue in which you are interested, opening the queue details page. It displays all of the tasks in the selected queue.\n\nDeleting tasks\n--------------\n\nOnce a worker completes a task, it needs to delete the task from the queue. If you see tasks remaining in a queue after a worker finishes processing them, it is likely that the worker failed; in this case, the tasks will be processed by another worker.\n\nYou can delete a list of tasks, such as that returned by `lease_task()`, simply by passing it to [`delete_tasks()`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.taskqueue.taskqueue#google.appengine.api.taskqueue.taskqueue.Queue.delete_tasks): \n\n from google.appengine.api import taskqueue\n\n q = taskqueue.Queue('pull-queue')\n tasks = q.lease_tasks(3600, 100)\n # Perform some work with the tasks here\n q.delete_tasks(tasks)\n\nAn end-to-end example of pull queues\n------------------------------------\n\nFor a simple but complete end-to-end example of using pull queues in Python, see\n[appengine-pullqueue-counter](https://github.com/GoogleCloudPlatform/appengine-pullqueue-counter)."]]