Unix Device File Emulation
blaine
frikker at gmail.com
Wed Apr 23 12:09:37 EDT 2008
On Apr 23, 11:17 am, "Ville M. Vainio" <vivai... at gmail.com> wrote:
> blaine wrote:
> > example usage: echo 'line 0 0 10 10' > /dev/screen
>
> > On the actual embedded device this is handled by a kernel module. We
> > can spit commands into it as fast as we can and the kernel module can
> > keep up. This is typical unix device file behavior.
>
> > Any suggestions or advice would be splendid. Thanks!
>
> Assuming you are on unix, have you considered FIFO's, os.mkfifo()?
Thank you - this is exactly what I need, I believe. I'm having a
problem though. The os.mkfifo() works fine, but when I read from the
file my blocking calls dont work as intended... See below:
# Fake Nokia Screen Emulator
import sys, os
class nokia_fkscrn:
def __init__(self, file):
if not os.path.exists(file):
os.mkfifo(file)
self.fifodev = open(file, 'r')
def read(self):
while 1:
r = self.fifodev.readline()
print r
nokia = nokia_fkscrn('dev.file')
nokia.read()
This works at first, but when I write to the 'dev.file' for the first
time, the text is displayed as intended, but then the program just
keeps spitting out blank lines. I can continue to write to the file
(using echo 'test\n' > dev.file) and this shows up in my output, but
amist a giant mass of scrolling blank lines. This also causes my CPU
usage to shoot up to 100%.
Any ideas? This is OS X 10.4
-Blaine
More information about the Python-list
mailing list