トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

BugTrack-その他のメモ/26

R備忘録 /状態空間モデリング/donlp2/その他のメモ

Pyro - Python Remote Objects

  • 投稿者: みゅ
  • カテゴリ: Python
  • 優先度: 普通
  • 状態: 完了
  • 日時: 2010年03月09日 21時26分30秒

内容

  • PYRO - Python Remote Objects
  • これでサーバーが立てられる
  • 複数コネクションも張れる.スレッドになるぽい.

Server

import Pyro.core
import time

class HelloGen(Pyro.core.ObjBase):
	def __init__(self):
		Pyro.core.ObjBase.__init__(self)
	def hi(self, name):
		time.sleep(10)
		return "Hi " + name + ", How's going?"

Pyro.core.initServer()
daemon = Pyro.core.Daemon()
uri = daemon.connect(HelloGen(), "hello")

print "The daemon runs on port:", daemon.port
print "The object's uri is:", uri

daemon.requestLoop()
  • 実行すると
$ python Pyro01.py
The daemon runs on port: 7766
The object's uri is: PYRO://127.0.0.1:7766/**********

Client

import Pyro.core

# finds object automatically if you're running the Name Server.
jokes = Pyro.core.getProxyForURI("PYRO://127.0.0.1:7766/**********")

jokes.hi("test")
"Hi test, How's going?"
  • あるいは
import Pyro.core

# finds object automatically if you're running the Name Server.
jokes = Pyro.core.getProxyForURI("PYROLOC://127.0.0.1:7766/hello")

jokes.hi("test")
"Hi test, How's going?"

コメント