[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Other access for information variables (except 'who')
From: |
ผศ.ดร.ศุภชัย วรพจน์พิศุทธิ์ |
Subject: |
Other access for information variables (except 'who') |
Date: |
Mon, 13 Dec 2004 16:53:37 +0700 (ICT) |
I am writing an IDE for my octave classroom using python. I use two
threads with stdin pipe and stdout/stderr pipe for sending commands to
'octave -i' and receiving result or error back respectively. The result
is processed by simple regular expression in order to remove command
prompt 'octave X:>'.
But I still can't find the way to access the information of local
variables. The 'who -variables -long' is not appropriate to the concept
pipe.readline() I used. Any recommendation is welcome.
Thanks in advance
Supachai
----------------------------------------------------------
import threading,Queue,os,string,re
class ReadingPipe(threading.Thread):
def __init__(self, pipe, **kwds):
threading.Thread.__init__(self, **kwds)
self.inpipe = pipe
self.re = re.compile(r'octave:.> ')
self.running = True
self.start()
def close(self):
self.running = False
def run(self):
while self.running:
ans = self.inpipe.readline()
if ans != '\n':
print ''.join(self.re.split(ans))
self.inpipe.close()
class WritingPipe(threading.Thread):
def __init__(self, pipe, **kwds):
threading.Thread.__init__(self, **kwds)
self.queue = Queue.Queue()
self.outpipe = pipe
self.running = True
self.start()
def request(self,cmd):
self.queue.put(cmd)
def close(self):
self.running = False
def run(self):
while self.running:
cmd = self.queue.get()
self.outpipe.write(cmd)
self.outpipe.flush()
self.outpipe.close()
class OctaveCmd:
def __init__(self):
[pw,pr] = os.popen4('octave -i -q')
r = ReadingPipe(pr)
w = WritingPipe(pw)
self.r = r
self.w = w
def do(self,cmd):
self.w.request(cmd)
def close(self):
self.w.close()
self.r.close()
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Other access for information variables (except 'who'),
ผศ.ดร.ศุภชัย วรพจน์พิศุทธิ์ <=