21.12.2022 Views

python_para_desenvolvedores_2ed

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

356 Respostas dos exercícios VI

Pyro.core.initServer()

# norange=1 faz com que o Pyro sempre use a mesma porta

daemon = Pyro.core.Daemon(norange = 1)

# Define o limite de tempo

daemon.setTimeout(300)

uri = daemon.connect(Dist(),'dist')

daemon.requestLoop()

Cliente:

# -*- coding: latin1 -*-

import Pyro.core

# URL com a porta

url = 'PYROLOC://127.0.0.1:8888/dist'

proxy = Pyro.core.getProxyForURI(url)

# Teste com até dez elementos

for i in range(10):

print i + 1, '=>', proxy.tribonacci(i + 1)

Saída:

Pyro Client Initialized. Using Pyro V3.7

1 => [1]

2 => [1, 1]

3 => [1, 1, 2]

4 => [1, 1, 2, 4]

5 => [1, 1, 2, 4, 7]

6 => [1, 1, 2, 4, 7, 13]

7 => [1, 1, 2, 4, 7, 13, 24]

8 => [1, 1, 2, 4, 7, 13, 24, 44]

9 => [1, 1, 2, 4, 7, 13, 24, 44, 81]

10 => [1, 1, 2, 4, 7, 13, 24, 44, 81, 149]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!