Any_srv is a simple rpc library that is based off of async_chat. It
grew out of the desire to make metakit available to other processes
without have to manually expose all of it and to keep in sync with
future library changes.
To do this the client is 100% stupid. It has no knowledge about the
library and the server knows nothing except for importing it. This
means it could just as easily "serve" the string library as well as a
How it is managed is by using __getattr__ to capture requests in the
client process and remote them to the server. Anything that is
pickelable is sent back to the client. Otherwise effectively a
reference is sent back that the client can refer to. Iteratorable
libraries are also supported. So if you make a database request (like
in metakit), you can iterate through it's rows and get the data back
Start the server with:
Here is example client code:
String library exposed:
print mclient.split('fred barney wilma')
['fred', 'barney', 'wilma']
betty bambam dino
And just as easily Metakit exposed:
#Create a database:
db = mclient.storage("datafile.mk",1)
print 'Create a view'
vw = db.getas("people[first:S,last:S,bowling:I]")
print 'Add a couple of rows'
print 'Commit the changes to file:'
print 'Show a list of all people:'
for r in vw: print r.first(), r.last(),r.bowl()
2 things to think about:
1)Need to explicity kill (perhaps with a try: finally: block) the
object references. You can do that with: mclient.any_server_clean()
2)Currently, attributes as well as methods end in (), since everything
is remoted to the server.
The code is at version .01 a bit rough and needs to have more
features/documentation (like specifying a port and library to expose
but it seems to work well.
It is at: