Skip to content
Hlab, lab-197 edited this page Nov 13, 2012 · 1 revision

This page describes advanced twisted concepts and commands that may be required while writing complex servers or clients. You may want to read the introductory page before proceeding.

DeferredLock

DeferredLock is useful for controlling access to a shared resource. For example, suppose we have a server with a device named dev. Suppose dev allows users to measure quantities A or B by calling dev.measureA() or dev.measureB() respectively. The LabRAD server implements two settings for these measurements:

--server code

What happens if two clients try to access these settings simultaneously? If measurement commands take a long time to execute, chances are that measureB will be called before measureA is finished or vice versa. IF such a situation is not desired, we need to implement a restriction on accessing this device. Using DeferredLock will make sure that measureA is finished before measureB is called or vice versa.

--code with deferredlock implemented

This long form can be replaced with

self.lock.run(dev.measureA)