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 | |
5 """Defines the client RPC methods.""" | |
6 | |
7 import logging | |
8 import subprocess | |
9 import threading | |
10 | |
11 | |
12 class RPCMethods(object): | |
13 """Class exposing RPC methods.""" | |
14 | |
15 def __init__(self, server): | |
16 self.server = server | |
17 | |
18 def Echo(self, message): | |
19 """Simple RPC method to print and return a message.""" | |
20 logging.info('Echoing %s', message) | |
21 return 'echo ' + message | |
M-A Ruel
2015/02/03 18:50:24
I'd recommend return 'echo %s' % message in case s
Mike Meade
2015/02/03 19:06:28
Done.
| |
22 | |
23 def Subprocess(self, cmd): | |
24 """Run the commands in a subprocess. | |
25 | |
26 Returns: | |
27 (returncode, stdout, stderr). | |
28 """ | |
29 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
30 stderr=subprocess.PIPE) | |
31 stdout, stderr = p.communicate() | |
32 return (p.returncode, stdout, stderr) | |
33 | |
34 def Quit(self): | |
35 """Call server.shutdown in another thread. | |
36 | |
37 This is needed because server.shutdown waits for the server to actually | |
38 quit. However the server cannot shutdown until it completes handling this | |
39 call. Calling this in the same thread results in a deadlock. | |
40 """ | |
41 t = threading.Thread(target=self.server.shutdown) | |
42 t.start() | |
OLD | NEW |