-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
41 lines (34 loc) · 1.21 KB
/
test.py
File metadata and controls
41 lines (34 loc) · 1.21 KB
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
from __future__ import print_function
import random
import time
import Pyro4
@Pyro4.expose
class StockMarket(object):
def __init__(self, marketname, symbols):
self._name = marketname
self._symbols = symbols
def quotes(self):
while True:
symbol = random.choice(self.symbols)
yield symbol, round(random.uniform(5, 150), 2)
time.sleep(random.random()/2.0)
@property
def name(self):
return self._name
@property
def symbols(self):
return self._symbols
if __name__ == "__main__":
nasdaq = StockMarket("NASDAQ", ["AAPL", "CSCO", "MSFT", "GOOG"])
newyork = StockMarket("NYSE", ["IBM", "HPQ", "BP"])
# for example purposes we will access the daemon and name server ourselves and not use serveSimple
with Pyro4.Daemon() as daemon:
nasdaq_uri = daemon.register(nasdaq)
print(nasdaq_uri)
newyork_uri = daemon.register(newyork)
print(dir(Pyro4.locateNS()))
with Pyro4.locateNS() as ns:
ns.register("example.stockmarket.nasdaq", nasdaq_uri)
ns.register("example.stockmarket.newyork", newyork_uri)
print("Stockmarkets available.")
daemon.requestLoop()