| 1 | #coding=utf-8 |
|---|
| 2 | from twisted.internet import iocpreactor |
|---|
| 3 | iocpreactor.install() |
|---|
| 4 | from twisted.internet import reactor,defer |
|---|
| 5 | from twisted.spread import pb |
|---|
| 6 | import time,cPickle |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | def main(): |
|---|
| 10 | @defer.inlineCallbacks |
|---|
| 11 | def call(): |
|---|
| 12 | factory = pb.PBClientFactory() |
|---|
| 13 | reactor.connectTCP("localhost",12345,factory) |
|---|
| 14 | remoteD = yield factory.getRootObject() |
|---|
| 15 | for i in range(5): |
|---|
| 16 | begin = time.time() |
|---|
| 17 | val = {"hello":"hello"*100,"foo":"bar","baz":100,u"these are bytes":(1,2,3)} |
|---|
| 18 | defers2 = [remoteD.callRemote("bad", cPickle.dumps(val, 2)) for i in range(1000)] |
|---|
| 19 | for d in defers2: |
|---|
| 20 | yield d |
|---|
| 21 | end = time.time() |
|---|
| 22 | print end-begin |
|---|
| 23 | reactor.stop() |
|---|
| 24 | reactor.callLater(0,call) |
|---|
| 25 | reactor.run() |
|---|
| 26 | |
|---|
| 27 | if __name__ == "__main__": |
|---|
| 28 | main() |
|---|