1. Michael Bayer
  2. dogpile.cache
  3. Issues
Issue #57 resolved

util.coerce_string_conf should coerce floats?

created an issue

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.


from dogpile.cache import make_region

myregion = make_region()

myconfig = {

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'

Comments (3)

  1. Michael Bayer repo owner

    yeah I struggle with this coerce string thing in various projects, I've come up with a better solution for SQLAlchemy that allows explicit schemas per backend, but over here, certainly just looking for a decimal point and coercing to float in that case is a great solution for now, so feel free to send a pullreq.

  2. Log in to comment