Commit 51f1dfd4 authored by Amos Latteier's avatar Amos Latteier

added a trigger callback arg.

parent 7f20fdae
...@@ -8,18 +8,19 @@ TupleType=type(()) ...@@ -8,18 +8,19 @@ TupleType=type(())
class OutputPipe: class OutputPipe:
def __init__(self): def __init__(self,callback=None):
lock=thread.allocate_lock() lock=thread.allocate_lock()
self._r=lock.release self._r=lock.release
self._a=lock.acquite self._a=lock.acquire
self._buf=[] self._buf=[]
self._callback=callback
def write(self, text): def write(self, text):
self._a() self._a()
try: try:
self._buf.append(text) self._buf.append(text)
finally: self._r() finally: self._r()
Wakeup() Wakeup(self._callback)
def close(self): def close(self):
self._a() self._a()
...@@ -35,7 +36,7 @@ class OutputPipe: ...@@ -35,7 +36,7 @@ class OutputPipe:
Return None if the pipe is open but has no data. Return None if the pipe is open but has no data.
Return an empty string if the pipe is closed. Return an empty string if the pipe is closed.
""" """
print "read from pipe"
self._a() self._a()
try: try:
b=self._buf b=self._buf
......
...@@ -8,18 +8,19 @@ TupleType=type(()) ...@@ -8,18 +8,19 @@ TupleType=type(())
class OutputPipe: class OutputPipe:
def __init__(self): def __init__(self,callback=None):
lock=thread.allocate_lock() lock=thread.allocate_lock()
self._r=lock.release self._r=lock.release
self._a=lock.acquite self._a=lock.acquire
self._buf=[] self._buf=[]
self._callback=callback
def write(self, text): def write(self, text):
self._a() self._a()
try: try:
self._buf.append(text) self._buf.append(text)
finally: self._r() finally: self._r()
Wakeup() Wakeup(self._callback)
def close(self): def close(self):
self._a() self._a()
...@@ -35,7 +36,7 @@ class OutputPipe: ...@@ -35,7 +36,7 @@ class OutputPipe:
Return None if the pipe is open but has no data. Return None if the pipe is open but has no data.
Return an empty string if the pipe is closed. Return an empty string if the pipe is closed.
""" """
print "read from pipe"
self._a() self._a()
try: try:
b=self._buf b=self._buf
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment