dynobase-icon
Dynobase

Error: can't pickle thread.lock objects typeerror boto3 python dynamodb

Rafal Wilinski

Answered by Rafal Wilinski

Last updated: October 23rd, 2026

Solution

“Can’t pickle thread lock objects” often occurs when multiprocessing or a task queue tries to serialize a boto3 client, resource, session, or an object that contains one. This is Python process-transfer behavior, not a DynamoDB serialization error. Create the client inside the worker instead.

from concurrent.futures import ProcessPoolExecutor
import boto3

def fetch_order(order_id):
    session = boto3.session.Session(region_name="us-east-1")
    db = session.client("dynamodb")
    return db.get_item(TableName="Orders", Key={"id": {"S": order_id}}).get("Item")

if __name__ == "__main__":
    with ProcessPoolExecutor() as pool:
        items = list(pool.map(fetch_order, ["123", "456"]))

Pass strings, numbers, and plain task dictionaries across the process boundary. A bound method can still capture self and its client, so inspect the whole object being submitted. For repeated tasks, a process initializer can create one client per worker.

Boto3 clients must not be shared across processes. Resources and sessions also have threading restrictions. Replacing a lock with a semaphore does not make the client safe to serialize; keep network clients local to the execution context that owns them.

See Python SDK usage and AWS documentation.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.