Skip to content

Commit

Permalink
clarified object creation a bit more in instancemode example
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Jan 23, 2021
1 parent 90dcac9 commit e0d8d86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/instancemode/Readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
This example shows the use of the instance_mode option when exposing a class.

The client will report the id of the object that handled the request.
The server will print this as well, but will also show exactly when Pyro is
creating a new instance of your server class. This makes it more clear in
situations where Python itself is recycling objects and therefore
ending up with the same id.

Please make sure a name server is running somewhere first,
before starting the server and client.
2 changes: 1 addition & 1 deletion examples/instancemode/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
print("Showing the different instancing modes.")
print("The number printed, is the id of the instance that handled the call.")

print("\n-----PERCALL (different number possible every time) -----")
print("\n-----PERCALL (different number *possible* every time) -----")
with Proxy("PYRONAME:instance.percall") as p:
print(p.msg("hello1"))
print(p.msg("hello1"))
Expand Down
6 changes: 6 additions & 0 deletions examples/instancemode/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

@behavior(instance_mode="single")
class SingleInstance(object):
def __init__(self):
print("created SingleInstance instance with id", id(self))
@expose
def msg(self, message):
print("[%s] %s.msg: %s" % (id(self), self.__class__.__name__, message))
Expand All @@ -11,6 +13,8 @@ def msg(self, message):

@behavior(instance_mode="session", instance_creator=lambda clazz: clazz.create_instance())
class SessionInstance(object):
def __init__(self):
print("created SessionInstance instance with id", id(self))
@expose
def msg(self, message):
print("[%s] %s.msg: %s" % (id(self), self.__class__.__name__, message))
Expand All @@ -24,6 +28,8 @@ def create_instance(cls):

@behavior(instance_mode="percall")
class PercallInstance(object):
def __init__(self):
print("created PercallInstance instance with id", id(self))
@expose
def msg(self, message):
print("[%s] %s.msg: %s" % (id(self), self.__class__.__name__, message))
Expand Down

0 comments on commit e0d8d86

Please sign in to comment.