The naming problem, need help

In the recent unreleased async_timeout version there are two ways to create a timeout:

async with timeout(5) as cm:
    # schedule timeout for 5 seconds after the current time


loop = asyncio.get_running_loop()
when = loop.time() + 5
async with timeout_at(when) as cm:
    # schedule timeout at when exact time;
    # in this case the same as above example

So far so good.
I want to reschedule already existing timeout, again a) for a delay and b) at absolute time.
The version on master uses cm.shift() and cm.shift_at() names. I’m not very happy with it.

The proper naming might be reschedule() / reschedule_at() but the word is too long I think. Another candidate is reusing timeout() / timeout_at(), e.g.

async with timeout(5) as cm:
    await asyncio.sleep(2)
    cm.timeout(5)  # extend the timeout for 5 seconds from now

Thesaurus suggests other words like retard or linger, I really don’t know what is better for native English speaker.

Suggestions for the naming are welcome!

Neither word is a good idea.

  • The verb retard has strong negative associations (retarded is used as an insult, less advanced in mental, physical, or social development than is usual for one’s age). It’s not a term I’d ever associate with a timer.
  • linger is also wrong; it carries with a sense of sticking around when one should really already have left. The dictionary definition is stay in a place longer than necessary because of a reluctance to leave.

I think shift_by() and shift_to() are much better. The point in time at which the timer will fire is shifted (a very common term for moving a scheduled point in time), either by a certain amount or to a specific point in time. The two names are also easy to distinguish.

1 Like


Is it ok to use shift_by for shifting by a delay from now?
The implementation is bare the following:

def shift_by(self, delay):
    now = self._loop.time()
    self.shift_to(now + delay)

Are timeout() and timeout_at() good names?
We should stick with timeout at least for a while for backward compatibility, timeout_at can be replaced freely. Also there is an option to add an alias for timeout with deprecation the latter.

I don’t see a reason to introduce a different method name. timeout and timeout_at cover the functionality you specified already; they do not care about previous timeout value, just override them with new ones.

I’d recommend extend or extend_by for extending current timeout by additional duration.

async with timeout(5) as cm: # this is now+5
    await asyncio.sleep(2)
    cm.extend(5)  # extend the timeout for 5 seconds from previous value, ie previous timeout+5

Hmm, cm.extend(delay) is as new as cm.shift(delay)

I was asking about top-level timeout() / timeout_at() functions.
shift_by() and shift_to() methods seems good.

How about postpone() / postpone_at()? Or maybe snooze(for=<5min/offset>) / snooze_at(to=<5pm/absolutev value>)