def save(self, force=False):
from time import time<EOL>from datetime import datetime<EOL>savefreq = TaskDB.get_option("<STR_LIT>", <NUM_LIT:2>, int)<EOL>if self.lastsave is not None:<EOL><INDENT>delta = (datetime.fromtimestamp(time()) -<EOL>datetime.fromtimestamp(self.lastsave)) <EOL>elapsed = int(delta.total_seconds()/<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>elapsed = savefreq + <NUM_LIT:1><EOL><DEDENT>if elapsed > savefreq or force:<EOL><INDENT>if not writeable:<EOL><INDENT>self.lastsave = time()<EOL>msg.std("<STR_LIT>", <NUM_LIT:2>)<EOL>return<EOL><DEDENT>import json<EOL>try:<EOL><INDENT>entities, compkeys = _json_clean(self.entities)<EOL>jdb = {"<STR_LIT>": entities,<EOL>"<STR_LIT>": compkeys,<EOL>"<STR_LIT>": self.uuids}<EOL>with open(self.dbpath, '<STR_LIT:w>') as f:<EOL><INDENT>json.dump(jdb, f)<EOL><DEDENT><DEDENT>except: <EOL><INDENT>from acorn.msg import err<EOL>import sys<EOL>raise<EOL>err("<STR_LIT>".format(*sys.exc_info()[<NUM_LIT:0>:<NUM_LIT:2>]))<EOL><DEDENT>self.lastsave = time()<EOL><DEDENT>
Serializes the database file to disk.

        Args:
            force (bool): when True, the elapsed time since last save is ignored
                and the database is saved anyway (subject to global
                :data:`writeable` setting).