Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: testing/legion/client_rpc_methods.py

Issue 890773003: Adding the initial code for Omnibot multi-machine support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Doing a little refactoring and changes. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 import StringIO
11
12
13 class RPCMethods(object):
14 """Class exposing RPC methods."""
15
16 def __init__(self, server):
17 self.server = server
18
19 def Echo(self, message):
20 """Simple RPC method to print and return a message."""
21 logging.info('Echoing %s', message)
22 return 'echo ' + message
23
24 def Subprocess(self, cmd):
25 """Run the commands in a subprocess.
26
27 Returns:
28 (returncode, stdout, stderr).
29 """
30 stdout = StringIO.StringIO()
31 stderr = StringIO.StringIO()
32 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
33 stderr=subprocess.PIPE)
34
35 while p.poll() is None:
36 _stdout, _stderr = p.communicate()
37 stdout.write(_stdout)
38 stderr.write(_stderr)
39
40 stdout.seek(0)
41 stderr.seek(0)
42 return (p.returncode, stdout.read(), stderr.read())
43
44 def Quit(self):
45 """Call server.shutdown in another thread.
46
47 This is needed because server.shutdown waits for the server to actually
48 quit. However the server cannot shutdown until it completes handling this
49 call. Calling this in the same thread results in a deadlock.
50 """
51 t = threading.Thread(target=self.server.shutdown)
52 t.start()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698