Skip to content

Commit e0d8d86

Browse files
committed
clarified object creation a bit more in instancemode example
1 parent 90dcac9 commit e0d8d86

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

examples/instancemode/Readme.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
This example shows the use of the instance_mode option when exposing a class.
22

3+
The client will report the id of the object that handled the request.
4+
The server will print this as well, but will also show exactly when Pyro is
5+
creating a new instance of your server class. This makes it more clear in
6+
situations where Python itself is recycling objects and therefore
7+
ending up with the same id.
8+
39
Please make sure a name server is running somewhere first,
410
before starting the server and client.

examples/instancemode/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
print("Showing the different instancing modes.")
44
print("The number printed, is the id of the instance that handled the call.")
55

6-
print("\n-----PERCALL (different number possible every time) -----")
6+
print("\n-----PERCALL (different number *possible* every time) -----")
77
with Proxy("PYRONAME:instance.percall") as p:
88
print(p.msg("hello1"))
99
print(p.msg("hello1"))

examples/instancemode/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

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

2529
@behavior(instance_mode="percall")
2630
class PercallInstance(object):
31+
def __init__(self):
32+
print("created PercallInstance instance with id", id(self))
2733
@expose
2834
def msg(self, message):
2935
print("[%s] %s.msg: %s" % (id(self), self.__class__.__name__, message))

0 commit comments

Comments
 (0)