From a48302e09c7600ca0c646a9f2b7ce498cc0e2a6c Mon Sep 17 00:00:00 2001 From: seungwoo <30397543+seunwoolee@users.noreply.github.com> Date: Wed, 4 Nov 2020 15:41:19 +0900 Subject: [PATCH] add time sleep --- Chapter 04/lockExample.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Chapter 04/lockExample.py b/Chapter 04/lockExample.py index cd25cb6..915493f 100644 --- a/Chapter 04/lockExample.py +++ b/Chapter 04/lockExample.py @@ -12,7 +12,8 @@ def workerA(): while counter < 1000: counter += 1 print("Worker A is incrementing counter to {}".format(counter)) - + sleepTime = random.randint(0, 1) + time.sleep(sleepTime) finally: lock.release() @@ -23,7 +24,8 @@ def workerB(): while counter > -1000: counter -= 1 print("Worker B is decrementing counter to {}".format(counter)) - + sleepTime = random.randint(0, 1) + time.sleep(sleepTime) finally: lock.release()