我正在使用下面的代码来链接到couchDb实例的链接,所以如果数据库很慢,我可以测试GUI会发生什么。
# coding=utf8 slowCoach.py - a server that delays every message
# thus making the database crawl.
import eventlet
from time import sleep
def closed_callback():
print "called back"
def forward(source, dest, cb = lambda: None):
"""Forwards bytes unidirectionally from source to dest"""
while True:
d = source.recv(32384)
if d == '':
cb()
break
sleep(0.3)
dest.sendall(d)
listener = eventlet.listen(('localhost', 5981 ))
while True:
client, addr = listener.accept()
server = eventlet.connect(('192.168.0.1',5984))
# two unidirectional forwarders make a bidirectional one
eventlet.spawn_n(forward, client, server, closed_callback)
eventlet.spawn_n(forward, server, client)
代码基于端口转发器示例。
当我读取,删除和更新文档时,它按预期工作,但是当我插入GUI时挂起。当我直接链接,错过上面的代码时,插入工作就好了!
与数据库通信的Python代码是couchDB-python(http://code.google.com/p/couchdb-python/),BOTH保存并插入执行以下语句
try:
self.db.save(dic)
except couchdb.ResourceConflict: # wrong _rev - updated by someone else
return False
for fld in ['_id','_rev']: # set id and rev to current values
value = dic[fld]
setattr(self, fld, value)
self._status = CouchObject.CLEAN
return self
然而一个是有效的,另一个则没有。有没有人有任何关于如何调试这个或者可能出错的提示?
答案 0 :(得分:1)
要回答我自己的问题 - 我应该从eventlet导入睡眠。没有它,绿色线程锁定,东西丢失。我在调用者中也有类似的问题,在上次收到之前将下一条消息发送到沙发,谁知道谁得到了什么回复!