Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
Latest commit
41 lines (34 loc) · 1.21 KB
/
Copy pathtest.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__ importprint_function
importrandom
importtime
importPyro4
@Pyro4.expose
classStockMarket(object):
def__init__(self, marketname, symbols):
self._name=marketname
self._symbols=symbols
defquotes(self):
whileTrue:
symbol=random.choice(self.symbols)
yieldsymbol, round(random.uniform(5, 150), 2)
time.sleep(random.random()/2.0)
@property
defname(self):
returnself._name
@property
defsymbols(self):
returnself._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
withPyro4.Daemon() asdaemon:
nasdaq_uri=daemon.register(nasdaq)
print(nasdaq_uri)
newyork_uri=daemon.register(newyork)
print(dir(Pyro4.locateNS()))
withPyro4.locateNS() asns:
ns.register("example.stockmarket.nasdaq", nasdaq_uri)
ns.register("example.stockmarket.newyork", newyork_uri)
print("Stockmarkets available.")
daemon.requestLoop()