How to use the locket.LockError function in locket

To help you get started, we’ve selected a few locket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwilliamson / locket.py / tests / locker.py View on Github external
if __name__ == "__main__":
    print(os.getpid())
    lock_path = sys.argv[1]
    if sys.argv[2] == "None":
        timeout = None
    else:
        timeout = float(sys.argv[2])
    lock = locket.lock_file(lock_path, timeout=timeout)

    _print("Send newline to stdin to acquire")
    sys.stdin.readline()
    try:
        lock.acquire()
    except locket.LockError:
        _print("LockError")
        exit(1)
    _print("Acquired")

    _print("Send newline to stdin to release")
    sys.stdin.readline()
    lock.release()
    _print("Released")
github mwilliamson / locket.py / tests / locket_tests.py View on Github external
def thread_cannot_obtain_lock_using_same_object_twice_without_release(lock_path):
    with locket.lock_file(lock_path, timeout=0) as lock:
        try:
            lock.acquire()
            assert False, "Expected LockError"
        except locket.LockError:
            pass
github OpenTreeOfLife / opentree / curator / controllers / default.py View on Github external
try:
            with locket.lock_file(NEXSON_LOCKFILEPATH, timeout=0):
                if not os.path.exists(NEXSON_DONE_FILEPATH):
                    try:
                        dfj = get_ot_study_info_from_nexml(NEXML_FILEPATH,
                                                           nexson_syntax_version=NEXSON_VERSION)
                    except:
                        raise HTTP(400, T("Submitted data is not a valid NeXML file, or cannot be converted."))
                    out = codecs.open(NEXSON_FILEPATH, 'w', encoding='utf-8')
                    json.dump(dfj, out, indent=0, sort_keys=True)
                    out.write('\n')
                    out.close()
                    out = open(NEXSON_DONE_FILEPATH, 'w')
                    out.write('0\n')
                    out.close()
        except locket.LockError:
            return HTTP(102, "Conversion to NexSON still running")
    if output in ['nexson', 'ot:nexson']:
        response.view = 'generic.json'
        nex = json.load(codecs.open(NEXSON_FILEPATH, 'rU', encoding='utf-8'))
        num_trees = count_num_trees(nex, NEXSON_VERSION)
        r = {'data': nex}
        bundle_properties = json.load(codecs.open(RETURN_ATT_FILEPATH, 'rU', encoding='utf-8'))
        try:
            dd = bundle_properties.get('dataDeposit')
            if dd:
                n = nex.get('nex:nexml') or nex['nex']
                add_resource_meta(n, "ot:dataDeposit", dd, NEXSON_VERSION)
        except:
            pass
        r.update(bundle_properties)
        r['numberOfTrees'] = num_trees
github kizniche / Mycodo / mycodo / controller_input.py View on Github external
self.trigger_cond = True
                        while self.next_measurement < now:
                            self.next_measurement += self.period

                    # if signaled and a pre output is set up correctly, turn the
                    # output on or on for the set duration
                    if (self.get_new_measurement and
                            self.pre_output_setup and
                            not self.pre_output_activated):

                        # Set up lock
                        self.input_lock = locket.lock_file(self.lock_file, timeout=120)
                        try:
                            self.input_lock.acquire()
                            self.pre_output_locked = True
                        except locket.LockError:
                            self.logger.error("Could not acquire input lock. Breaking for future locking.")
                            try:
                                os.remove(self.lock_file)
                            except OSError:
                                self.logger.error("Can't delete lock file: Lock file doesn't exist.")

                        self.pre_output_timer = time.time() + self.pre_output_duration
                        self.pre_output_activated = True

                        # Only run the pre-output before measurement
                        # Turn on for a duration, measure after it turns off
                        if not self.pre_output_during_measure:
                            output_on = threading.Thread(
                                target=self.control.output_on,
                                args=(self.pre_output_id,
                                      self.pre_output_duration,))

locket

File-based locks for Python on Linux and Windows

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis