diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-02-21 04:46:49 +0000 |
---|---|---|
committer | <> | 2014-08-04 21:38:17 +0000 |
commit | f3765db04b903b3671733e07cf1541a51966dd14 (patch) | |
tree | defcc3c47d9b8bd78b97dcc04ee779a758d37b1c /demo4/child.py | |
download | posix-ipc-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_python-packages_posix-ipc-tarball/posix_ipc-0.9.8.tar.gz.HEADposix_ipc-0.9.8master
Diffstat (limited to 'demo4/child.py')
-rw-r--r-- | demo4/child.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/demo4/child.py b/demo4/child.py new file mode 100644 index 0000000..cbceb37 --- /dev/null +++ b/demo4/child.py @@ -0,0 +1,21 @@ +import posix_ipc +import time +import sys +import random + +# The parent passes the semaphore's name to me. +name = sys.argv[1] + +print('Child: waiting to aquire semaphore ' + name) + +with posix_ipc.Semaphore(name) as sem: + print('Child: semaphore ' + sem.name + ' aquired; holding for 3 seconds.') + + # Flip a coin to determine whether or not to bail out of the context. + if random.randint(0, 1): + print("Child: raising ValueError to demonstrate unplanned context exit") + raise ValueError + + time.sleep(3) + + print('Child: gracefully exiting context (releasing the semaphore).') |