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. |
| 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 import logging |
| 11 import subprocess |
| 12 import threading |
| 13 |
| 14 |
| 15 class RPCMethods(object): |
| 16 """The class exposing RPC methods.""" |
| 17 |
| 18 def __init__(self, server): |
| 19 self.server = server |
| 20 |
| 21 def Echo(self, message): |
| 22 """Simple RPC method to print and return a message.""" |
| 23 logging.info('Echoing %s', message) |
| 24 return 'echo ' + message |
| 25 |
| 26 def Subprocess(self, cmd): |
| 27 """Run the commands in a subprocess. |
| 28 |
| 29 Note that stdout and stderr are passed to this process' stdout and stderr |
| 30 and only the return code is returned. |
| 31 |
| 32 Args: |
| 33 cmd: A command list to pass to subprocess.call. |
| 34 """ |
| 35 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 36 stderr=subprocess.PIPE) |
| 37 p.wait() |
| 38 return (p.returncode, p.stdout.read(), p.stderr.read()) |
| 39 |
| 40 def Quit(self): |
| 41 """Call server.shutdown in another thread. |
| 42 |
| 43 This is needed because server.shutdown waits for the server to actually |
| 44 quit. However the server cannot shutdown until it completes handling this |
| 45 call. Calling this in the same thread results in a deadlock. |
| 46 """ |
| 47 t = threading.Thread(target=self.server.shutdown) |
| 48 t.start() |
OLD | NEW |