Last active
February 22, 2019 12:05
-
-
Save v-ko/fe500878c14cc381c2fa324b376ed18e to your computer and use it in GitHub Desktop.
Python Pyro RPC example client and server with a separate thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys, struct | |
import Pyro4 | |
sys.excepthook = Pyro4.util.excepthook | |
interface = Pyro4.Proxy("PYRO:interface@localhost:53546") | |
print(interface.test()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Pyro4 | |
import threading | |
import time | |
@Pyro4.expose | |
@Pyro4.behavior(instance_mode="single") | |
class Interface(object): | |
def test(self): | |
res = "test_string" | |
print("Test returning:"+res) | |
return res | |
class Server(): | |
def enable(self): | |
self.daemon = Pyro4.Daemon(port=53546) | |
self.daemon.register(Interface, "interface") | |
self.thread = threading.Thread(target=self.daemonLoop) | |
self.thread.start() | |
print("Started thread") | |
def disable(self): | |
print("Called for daemon shutdown") | |
self.daemon.shutdown() | |
def daemonLoop(self): | |
self.daemon.requestLoop() | |
print("Daemon has shut down no prob") | |
# Run the server for 30 sec (I was too lazy to write a main() func) | |
s = Server() | |
s.enable() | |
time.sleep(60) | |
s.disable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment