如果你不需要,一个可能的解决方案是使用Pyro4而不是数据库。您可以使用下面的代码:
Tracker.py
import Pyro4
@Pyro4.expose
@Pyro4.behavior(instance_mode="single")
class Tracker(object):
def __init__(self):
self._id = None
def setId(self, value):
print "set well :)", value
self._id = value
print self._id
def getId(self):
print "returning", self._id
return self._id
daemon = Pyro4.Daemon()
uri = daemon.register(Tracker)
print("URI: ", uri)
daemon.requestLoop()
Status.py
import Pyro4
class Status(object):
def __init__(self, id):
self._id = id
self._pyro = None
def connect(self, target):
self._pyro = Pyro4.Proxy(target)
def updateId(self):
if (not self._pyro is None):
self._pyro.setId(self._id)
print "updated"
else:
print "please connect"
def getId(self):
if (not self._pyro is None):
return self._pyro.getId()
else:
print "please connect"
Success.py
from Status import *
class Success(Status):
def __init__(self):
super(Success,self).__init__(1)
Wait.py
from Status import *
class Wait(Status):
def __init__(self):
super(Wait,self).__init__(1)
Error.py
from Status import *
class Error(Status):
def __init__(self):
super(Error,self).__init__(3)
run.py
from Success import *
from Wait import *
from Error import *
#just an example
s = Success()
w = Wait()
e = Error()
s.connect("PYRO:[email protected]:51464")
s.updateId()
print s.getId()
w.connect("PYRO:[email protected]:51464")
w.updateId()
print s.getId()
e.connect("PYRO:[email protected]:51464")
e.updateId()
print s.getId()
当然,你需要使用不同的URI,但你应该有一个好主意,现在。使用Pyro,你也可以根据需要指定一个静态URI名称。
输出应该是:
$ c:\Python27\python.exe run.py
updated
1
updated
2
updated
3
HTH
但它使用三个不同的表右侧的可能吗?我将使用一个请求,一个用于响应,另一个用于错误。 –
是的。只要确保每个表都有一个带有自动增量的整数主键。 – shanmuga