Various Python code cleanups. (#3837)

This commit is contained in:
Si-Yuan
2019-02-03 10:16:24 -08:00
committed by Robert Nishihara
parent a1bcd2a4f5
commit 9295ab8f60
12 changed files with 177 additions and 261 deletions
+3 -15
View File
@@ -49,11 +49,7 @@ def format_error_message(exception_message, task_exception=False):
return "\n".join(lines)
def push_error_to_driver(worker,
error_type,
message,
driver_id=None,
data=None):
def push_error_to_driver(worker, error_type, message, driver_id=None):
"""Push an error message to the driver to be printed in the background.
Args:
@@ -63,12 +59,9 @@ def push_error_to_driver(worker,
on the driver.
driver_id: The ID of the driver to push the error message to. If this
is None, then the message will be pushed to all drivers.
data: This should be a dictionary mapping strings to strings. It
will be serialized with json and stored in Redis.
"""
if driver_id is None:
driver_id = ray.DriverID.nil()
data = {} if data is None else data
worker.raylet_client.push_error(driver_id, error_type, message,
time.time())
@@ -76,8 +69,7 @@ def push_error_to_driver(worker,
def push_error_to_driver_through_redis(redis_client,
error_type,
message,
driver_id=None,
data=None):
driver_id=None):
"""Push an error message to the driver to be printed in the background.
Normally the push_error_to_driver function should be used. However, in some
@@ -92,12 +84,9 @@ def push_error_to_driver_through_redis(redis_client,
on the driver.
driver_id: The ID of the driver to push the error message to. If this
is None, then the message will be pushed to all drivers.
data: This should be a dictionary mapping strings to strings. It
will be serialized with json and stored in Redis.
"""
if driver_id is None:
driver_id = ray.DriverID.nil()
data = {} if data is None else data
# Do everything in Python and through the Python Redis client instead
# of through the raylet.
error_data = ray.gcs_utils.construct_error_message(driver_id, error_type,
@@ -132,7 +121,7 @@ def is_function_or_method(obj):
Returns:
True if the object is an function or method.
"""
return (inspect.isfunction(obj) or inspect.ismethod(obj) or is_cython(obj))
return inspect.isfunction(obj) or inspect.ismethod(obj) or is_cython(obj)
def is_class_method(f):
@@ -367,7 +356,6 @@ def get_system_memory():
except ImportError:
pass
memory_in_bytes = None
if psutil_memory_in_bytes is not None:
memory_in_bytes = psutil_memory_in_bytes
elif sys.platform == "linux" or sys.platform == "linux2":