Using Async/Await with Pickle

Viewed 3632

I am new to async/await, and I came across a bit of confusion. Should pickle be awaited somehow?

For example, say I have the following async class methods:

async def get(self, key):
    redis = await self.getRedis()
    data = await redis.get(key)
    if not data:
        return None

    return pickle.loads(data)

async def set(self, key, value, ttlInSeconds):
    pickled = pickle.dumps(value)

    redis = await self.getRedis()
    await redis.setex(key, pickled, ttlInSeconds)

If I'm serializing or unserializing a large object, won't the entire loop block on pickle? For practical purposes, with smaller objects, is this momentary blocking acceptable? Thanks!

1 Answers
Related