From 908e6e427c3aa954dbb141eb42e3543088a0ab68 Mon Sep 17 00:00:00 2001 From: Zach Tibbitts Date: Wed, 6 Dec 2006 03:51:33 +0000 Subject: [PATCH] mmap examples --- sandbox/mmap_client.py | 12 ++++++++++++ sandbox/mmap_server.py | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100755 sandbox/mmap_client.py create mode 100755 sandbox/mmap_server.py diff --git a/sandbox/mmap_client.py b/sandbox/mmap_client.py new file mode 100755 index 000000000..1948b2571 --- /dev/null +++ b/sandbox/mmap_client.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python2.4 + +import mmap, os, time +mx = mmap.mmap(os.open('xxx',os.O_RDWR), 1) +last = None +while True: + mx.resize(mx.size()) + data = mx[:] + if data != last: + print data + last = data + time.sleep(1) \ No newline at end of file diff --git a/sandbox/mmap_server.py b/sandbox/mmap_server.py new file mode 100755 index 000000000..490dc61cc --- /dev/null +++ b/sandbox/mmap_server.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python2.4 + +fileob = open('xxx','w') +while True: + data = raw_input('Enter some text:') + fileob.seek(0) + fileob.write(data) + fileob.truncate() + fileob.flush() \ No newline at end of file