File: client.py

package info (click to toggle)
pyro5 5.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,124 kB
  • sloc: python: 14,328; makefile: 161; sh: 66; javascript: 62
file content (63 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import time
import warnings
import serpent
from Pyro5.api import Proxy, config


warnings.filterwarnings("ignore")

print("Enter the server's uri that was printed:")
uri = input().strip()

datasize = 5 * 1024 * 1024  # 5 mb


def do_test(data):
    assert len(data) == datasize
    totalsize = 0

    with Proxy(uri) as obj:
        obj._pyroBind()

        begin = time.time()
        for i in range(10):
            print("transferring %d bytes" % datasize)
            size = obj.transfer(data)
            assert size == datasize
            totalsize += datasize
        duration = time.time() - begin

        totalsize = float(totalsize)
        print("It took %.2f seconds to transfer %d mb." % (duration, totalsize / 1024 / 1024))
        print("That is %.0f kb/sec. = %.1f mb/sec. (serializer: %s)" %
              (totalsize / 1024 / duration, totalsize / 1024 / 1024 / duration, config.SERIALIZER))


def do_test_chunks():
    with Proxy(uri) as p:
        totalsize = 0
        begin = time.time()
        for chunk in p.download_chunks(datasize*10):
            chunk = serpent.tobytes(chunk)  # in case of serpent encoded bytes
            totalsize += len(chunk)
            print(".", end="", flush=True)
        assert totalsize == datasize*10
        duration = time.time() - begin
        totalsize = float(totalsize)
        print("\nIt took %.2f seconds to transfer %d mb." % (duration, totalsize / 1024 / 1024))
        print("That is %.0f kb/sec. = %.1f mb/sec. (serializer: %s)" %
              (totalsize / 1024 / duration, totalsize / 1024 / 1024 / duration, config.SERIALIZER))


data = 'x' * datasize
print("\n\n----test with string data----")
do_test(data)
print("\n\n----test with byte data----")
data = b'x' * datasize
do_test(data)
data = bytearray(b'x' * datasize)
print("\n\n----test with bytearray data----")
do_test(data)
print("\n\n----test download via iterator----")
do_test_chunks()
print("\n\n (tip: also see the 'filetransfer' example for more efficient ways to transfer large amounts of binary data)")