1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
import time
import threading
from Pyro5.api import expose, behavior, oneway, serve, config
@expose
@behavior(instance_mode="single")
class Server(object):
def __init__(self):
self.callcount = 0
def reset(self):
self.callcount = 0
def getcount(self):
return self.callcount # the number of completed calls
def getconfig(self):
return config.as_dict()
def delay(self):
threadname = threading.current_thread().name
print("delay called in thread %s" % threadname)
time.sleep(1)
self.callcount += 1
return threadname
@oneway
def onewaydelay(self):
threadname = threading.current_thread().name
print("onewaydelay called in thread %s" % threadname)
time.sleep(1)
self.callcount += 1
# main program
config.SERVERTYPE = "undefined"
servertype = input("Servertype threaded or multiplex (t/m)?")
if servertype == "t":
config.SERVERTYPE = "thread"
else:
config.SERVERTYPE = "multiplex"
serve({
Server: "example.servertypes"
})
|