00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import threading
00019
00020 import OpenRTM
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class PublisherNew(OpenRTM.PublisherBase):
00039 """
00040 """
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 def __init__(self, consumer, property):
00059 self._data = self.NewData()
00060 self._consumer = consumer
00061 self._running = True
00062 self._thread = threading.Thread(target=self.run)
00063 self._thread.start()
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 def __del__(self):
00079 del self._consumer
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 def update(self):
00096 if not self._data._cond.acquire(0):
00097 return
00098
00099 self._data._updated = True
00100 self._data._cond.notify()
00101 self._data._cond.release()
00102 return
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 def run(self):
00117 while self._running:
00118 self._data._cond.acquire()
00119
00120 while not self._data._updated and self._running:
00121 self._data._cond.wait()
00122
00123 if self._data._updated:
00124 self._consumer.push()
00125 self._data._updated = False
00126
00127 self._data._cond.release()
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 def release(self):
00148 if not self._data._cond.acquire(0):
00149 return
00150
00151 self._running = False
00152 self._data._cond.notify()
00153 self._data._cond.release()
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 class NewData:
00165 def __init__(self):
00166 self._mutex = threading.RLock()
00167 self._cond = threading.Condition(self._mutex)
00168 self._updated = False