Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 """Client RPC Methods. | |
|
Marc-Antoine Ruel (Google)
2015/01/30 21:58:39
This is not informative. "client_rpc_methods.py" p
Mike Meade
2015/02/03 01:18:08
Done.
| |
| 5 | |
| 6 The RPC methods made available on the client are all defined here in the | |
| 7 RPCMethods class. This class is made separate for easy maintenance and | |
| 8 method lookup. | |
| 9 """ | |
| 10 | |
| 11 import logging | |
| 12 import subprocess | |
| 13 import threading | |
| 14 | |
| 15 | |
| 16 class RPCMethods(object): | |
| 17 """The class exposing RPC methods.""" | |
| 18 | |
| 19 def __init__(self, server): | |
| 20 self.server = server | |
| 21 | |
| 22 def Echo(self, message): | |
| 23 """Simple RPC method to print and return a message.""" | |
| 24 logging.info('Echoing %s', message) | |
| 25 return 'echo ' + message | |
| 26 | |
| 27 def Subprocess(self, cmd): | |
| 28 """Run the commands in a subprocess. | |
| 29 | |
| 30 Note that stdout and stderr are passed to this process' stdout and stderr | |
| 31 and only the return code is returned. | |
| 32 | |
| 33 Args: | |
| 34 cmd: A command list to pass to subprocess.call. | |
| 35 """ | |
| 36 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
| 37 stderr=subprocess.PIPE) | |
| 38 p.wait() | |
|
Marc-Antoine Ruel (Google)
2015/01/30 21:58:39
This will hang. You need to use .communicate()
Mike Meade
2015/02/03 01:18:08
Done.
| |
| 39 return (p.returncode, p.stdout.read(), p.stderr.read()) | |
| 40 | |
| 41 def Quit(self): | |
| 42 """Call server.shutdown in another thread. | |
| 43 | |
| 44 This is needed because server.shutdown waits for the server to actually | |
| 45 quit. However the server cannot shutdown until it completes handling this | |
| 46 call. Calling this in the same thread results in a deadlock. | |
| 47 """ | |
| 48 t = threading.Thread(target=self.server.shutdown) | |
| 49 t.start() | |
| OLD | NEW |