inter thread/process synchronisation python conditions conditions can be used to synchronise the interaction between two or more threads or processes conditions objects support the concept of notification modelideal for shared data resource being accessed by multiple consumers and producers condition can be used to notify one or all of the waiting threads or processes that they can proceed (for example to read data from shared resourcethe methods available that support this arenotify(notifies one waiting thread which can then continue notify_all(notifies all waiting threads that they can continue wait(causes thread to wait until it has been notified that it can continue condition is always associated with an internal lock which must be acquired and released before the wait(and notify(methods can be called the condition supports the context manager protocol and can therefore be used via with statement (which is the most typical way to use conditionto obtain this lock for exampleto obtain the condition lock and call the wait method we might writewith conditioncondition wait(print('now we can proceed'the condition object is used in the following example to illustrate how producer thread and two consumer threads can cooperate dataresource class has been defined which will hold an item of data that will be shared between consumer and set of producers it also (internallydefines condition attribute note that this means that the condition is completely internalised to the dataresource classexternal code does not need to knowor be concerned withthe condition and its use instead external code can merely call the consumer(and producer(functions in separate threads as required the consumer(method uses with statement to obtain the (internallock on the condition object before waiting to be notified that the data is available in turn the producer(method also uses with statement to obtain lock on the condition object before generating the data attribute value and then notifying anything waiting on the condition that they can proceed note that although the consumer method obtains lock on the condition objectif it has to wait it will release the lock and re obtain the lock once it is notified that it can continue this is subtly that is often missed