':param bool event: If True, the \'manager.lock_acquired\' event will be fired after a lock is obtained'

@contextmanager
def acquire_lock(self, event=True):

    acquired = False
    try:
        if (not self._has_lock):
            if self.check_lock():
                with io.open(self.lockfile, encoding=u'utf-8') as f:
                    pid = f.read()
                print((u'Another    process    (%s)    is    running,    will    exit.' % pid.split(u'\n')[0]), file=sys.stderr)
                print((u"If    you're    sure    there    is    no    other    instance    running,    delete    %s" % self.lockfile), file=sys.stderr)
                sys.exit(1)
            self._has_lock = True
            self.write_lock()
            acquired = True
            if event:
                fire_event(u'manager.lock_acquired', self)
        (yield)
    finally:
        if acquired:
            self.release_lock()
            self._has_lock = False
