Skip to content

util.coerce_string_conf should coerce floats? #57

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Jeff Dairiki (dairiki)

Now that #9 has made it into release, I’m trying to use distributed_lock with the redis backend. I’ve discovered that one can not pleasantly configure lock_sleep to anything other than an integer or None when using configure_from_config (with a string-valued config dict, such as comes from a .ini settings file.) (Generally one wants to set lock_sleep to a value less than 1 second — e.g. the default is 0.1.)

My guess is that the simplest solution is to fix dogpile.cache.util.coerce_string_conf so that it coerces strings that look like floats to floats. I’m not quite sure whether that might screw something else up, however.

I'd be happy to produce a pull request if this is deemed the right way to proceed.


E.g.

from dogpile.cache import make_region

myregion = make_region()

myconfig = {
    "cache.backend":"dogpile.cache.redis",
    "cache.arguments.distributed_lock":"true",
    "cache.arguments.lock_timeout":"10",
    "cache.arguments.lock_sleep":"0.1",
}

myregion.configure_from_config(myconfig, "cache.")

print "lock_timeout = %r" % myregion.backend.lock_timeout
print "lock_sleep = %r" % myregion.backend.lock_sleep

myregion.get_or_create('somekey', lambda: 42)

which produces

lock_timeout = 10
lock_sleep = '0.1'

[traceback elided]
LockError: 'sleep' must be less than 'timeout'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions