2008年2月29日金曜日

threading.Condition.wait @ python

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
Timeoutをraiseしてほしいのですが・・・。

これは正しく動かない。waitが何で帰ってきたかを計時から判定するのは変。
取れているかもしれないのにTimeout扱いのときがある。

# We can't create a new resource, so we have to decide
# how we will wait for one to become available.
if timeoutSeconds:
# Raise an exception if a resource is not
# available within the given amount of seconds.
self.__availableCondition.wait(timeoutSeconds)
if (time.time() - startTime) >= timeoutSeconds:
raise TimeoutError(
"Unable to get resource within %s seconds"
% timeoutSeconds)


これにあるようにresultを用意するのは面倒だし。

condition.acquire()
try:
while not result:
condition.wait()
finally:
condition.release()


MLでもぎろんされたようだ。しかしここはreturnの値が問題としている。exceptionにすれば既存のコードに対する親和性は高いだろうに。

interruptもきかないらしい。ぎょえ~~。

0 件のコメント: