File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 11This 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+
39Please make sure a name server is running somewhere first,
410before starting the server and client.
Original file line number Diff line number Diff line change 33print ("Showing the different instancing modes." )
44print ("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) -----" )
77with Proxy ("PYRONAME:instance.percall" ) as p :
88 print (p .msg ("hello1" ))
99 print (p .msg ("hello1" ))
Original file line number Diff line number Diff line change 33
44@behavior (instance_mode = "single" )
55class 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 ())
1315class 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" )
2630class 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 ))
You can’t perform that action at this time.
0 commit comments