I just had a 30 minutes worth of debugging on a stupid mistake I made. I wanted to check the free space on the target server before I actually start to do the cloning of a database in the python framework we wrote for automating DBA tasks. The check was pretty simple:
1 2 3 4 5 |
self.datasize = int(_semaphore.get_meta('data_size')) with os.statvfs(self.host.mysql_dir) as _s: if self.datasize > (_s.f_bsize * _s.f_bavail) / 1024 : # The datasize is in kbytes while the statvfs returns bytes raise TaskError('Do not have enough space for cloning.') |
But this raised an error: AttributeError: __exit__
I’ve spent almost 30 minutes when I realized the os.statvfs returns and “old style” object which doesn’t have __exit__ method by default. [1]
Changed the code to not use with [2] fixed the problem:
1 2 3 4 |
_s = os.statvfs(self.host.mysql_dir) if self.datasize > (_s.f_bsize * _s.f_bavail) / 1024 : # The datasize is in kbytes while the statvfs returns bytes raise TaskError('Do not have enough space for cloning.') |
[1] object type in Python: http://docs.python.org/2/library/functions.html#object
[2] read more about with statement: http://www.python.org/dev/peps/pep-0343/
Recent comments