Remove unnecessary pip installs. (#21)

* Small cleanups in worker.py.

* Remove dependencies on subprocess32, graphviz, protobuf, and ipython.

* Retry starting the plasma manager if the port is in use.

* Whitespace

* Move start_plasma_manager into plasma.py.
This commit is contained in:
Robert Nishihara
2016-11-02 16:40:37 -07:00
committed by Philipp Moritz
parent 072f442c1f
commit 681ec570ba
8 changed files with 66 additions and 55 deletions
+49 -2
View File
@@ -1,6 +1,8 @@
import os
import socket
import ctypes
import os
import random
import socket
import subprocess
import time
Addr = ctypes.c_ubyte * 4
@@ -287,3 +289,48 @@ class PlasmaClient(object):
assert len(message_data) == PLASMA_ID_SIZE
break
return message_data
def start_plasma_manager(store_name, manager_name, redis_address, num_retries=5, use_valgrind=False):
"""Start a plasma manager and return the ports it listens on.
Args:
store_name (str): The name of the plasma store socket.
manager_name (str): The name of the plasma manager socket.
redis_address (str): The address of the Redis server.
use_valgrind (bool): True if the Plasma manager should be started inside of
valgrind and False otherwise.
Returns:
The process ID of the Plasma manager and the port that the manager is
listening on.
Raises:
Exception: An exception is raised if the manager could not be properly
started.
"""
plasma_manager_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../build/plasma_manager")
port = None
process = None
counter = 0
while counter < num_retries:
if counter > 0:
print("Plasma manager failed to start, retrying now.")
port = random.randint(10000, 65535)
command = [plasma_manager_executable,
"-s", store_name,
"-m", manager_name,
"-h", "127.0.0.1",
"-p", str(port),
"-r", redis_address]
if use_valgrind:
process = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + command)
else:
process = subprocess.Popen(command)
# This sleep is critical. If the plasma_manager fails to start because the
# port is already in use, then we need it to fail within 0.1 seconds.
time.sleep(0.1)
# See if the process has terminated
if process.poll() == None:
return process, port
counter += 1
raise Exception("Couldn't start plasma manager.")
+3 -28
View File
@@ -53,32 +53,6 @@ def assert_get_object_equal(unit_test, client1, client2, object_id, memory_buffe
unit_test.assertEqual(client1.get_metadata(object_id)[:],
client2.get_metadata(object_id)[:])
def start_plasma_manager(store_name, host_name, redis_port, use_valgrind=False):
"""Start a plasma manager and return the ports it listens on."""
plasma_manager_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/plasma_manager")
num_retries = 5
port = None
process = None
while num_retries >= 0:
port = random.randint(10000, 50000)
command = [plasma_manager_executable,
"-s", store_name,
"-m", host_name,
"-h", "127.0.0.1",
"-p", str(port),
"-r", "{addr}:{port}".format(addr="127.0.0.1", port=redis_port)]
print("Try to start plasma manager on port " + str(port))
if use_valgrind:
process = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + command)
else:
process = subprocess.Popen(command)
time.sleep(0.1)
# See if the process has terminated
if process.poll() == None:
return process, port
num_retries = num_retries - 1
raise Exception("Couldn't start plasma manager")
# Check if the redis-server binary is present.
redis_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../common/thirdparty/redis-3.2.3/src/redis-server")
if not os.path.exists(redis_path):
@@ -266,8 +240,9 @@ class TestPlasmaManager(unittest.TestCase):
time.sleep(0.1)
# Start two PlasmaManagers.
self.p4, self.port1 = start_plasma_manager(store_name1, manager_name1, redis_port, USE_VALGRIND)
self.p5, self.port2 = start_plasma_manager(store_name2, manager_name2, redis_port, USE_VALGRIND)
redis_address = "{}:{}".format("127.0.0.1", redis_port)
self.p4, self.port1 = plasma.start_plasma_manager(store_name1, manager_name1, redis_address, use_valgrind=USE_VALGRIND)
self.p5, self.port2 = plasma.start_plasma_manager(store_name2, manager_name2, redis_address, use_valgrind=USE_VALGRIND)
# Connect two PlasmaClients.
self.client1 = plasma.PlasmaClient(store_name1, manager_name1)