diff --git a/examples/rl_pong/driver.py b/examples/rl_pong/driver.py index 5bf784092..0d1813f03 100644 --- a/examples/rl_pong/driver.py +++ b/examples/rl_pong/driver.py @@ -32,19 +32,19 @@ def sigmoid(x): return 1.0 / (1.0 + np.exp(-x)) -def preprocess(I): +def preprocess(img): """Preprocess 210x160x3 uint8 frame into 6400 (80x80) 1D float vector.""" # Crop the image. - I = I[35:195] + img = img[35:195] # Downsample by factor of 2. - I = I[::2, ::2, 0] + img = img[::2, ::2, 0] # Erase background (background type 1). - I[I == 144] = 0 + img[img == 144] = 0 # Erase background (background type 2). - I[I == 109] = 0 + img[img == 109] = 0 # Set everything else (paddles, ball) to 1. - I[I != 0] = 1 - return I.astype(np.float).ravel() + img[img != 0] = 1 + return img.astype(np.float).ravel() def discount_rewards(r): diff --git a/python/ray/common/test/test.py b/python/ray/common/test/test.py index d3e648e85..1228d7571 100644 --- a/python/ray/common/test/test.py +++ b/python/ray/common/test/test.py @@ -46,8 +46,8 @@ SIMPLE_OBJECTS = (BASE_SIMPLE_OBJECTS + # Create some complex objects that cannot be serialized by value in tasks. -l = [] -l.append(l) +lst = [] +lst.append(lst) class Foo(object): @@ -55,7 +55,7 @@ class Foo(object): pass -BASE_COMPLEX_OBJECTS = [999 * "h", 999 * u"h", l, Foo(), +BASE_COMPLEX_OBJECTS = [999 * "h", 999 * u"h", lst, Foo(), 10 * [10 * [10 * [1]]]] LIST_COMPLEX_OBJECTS = [[obj] for obj in BASE_COMPLEX_OBJECTS] diff --git a/python/ray/serialization.py b/python/ray/serialization.py index 87c678f23..ab90fcc73 100644 --- a/python/ray/serialization.py +++ b/python/ray/serialization.py @@ -33,7 +33,7 @@ def check_serializable(cls): .format(cls)) try: obj = cls.__new__(cls) - except: + except Exception: raise RayNotDictionarySerializable("The class {} has overridden " "'__new__', so Ray may not be able " "to serialize it efficiently." diff --git a/python/ray/services.py b/python/ray/services.py index 2d1fcda3a..cf845a98b 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -66,18 +66,15 @@ def address(ip_address, port): def get_ip_address(address): - try: - ip_address = address.split(":")[0] - except: - raise Exception("Unable to parse IP address from address " - "{}".format(address)) + assert type(address) == str, "Address must be a string" + ip_address = address.split(":")[0] return ip_address def get_port(address): try: port = int(address.split(":")[1]) - except: + except Exception: raise Exception("Unable to parse port from address {}".format(address)) return port @@ -505,7 +502,7 @@ def start_ui(redis_address, stdout_file=None, stderr_file=None, cleanup=True): ui_process = subprocess.Popen(command, env=new_env, cwd=new_notebook_directory, stdout=stdout_file, stderr=stderr_file) - except: + except Exception: print("Failed to start the UI, you may need to run " "'pip install jupyter'.") else: diff --git a/python/ray/test/test_functions.py b/python/ray/test/test_functions.py index 105dbf184..3f6e4d978 100644 --- a/python/ray/test/test_functions.py +++ b/python/ray/test/test_functions.py @@ -60,7 +60,7 @@ try: def kwargs_throw_exception(**c): return () kwargs_exception_thrown = False -except: +except Exception: kwargs_exception_thrown = True try: @@ -68,7 +68,7 @@ try: def varargs_and_kwargs_throw_exception(a, b="hi", *c): return "{} {} {}".format(a, b, c) varargs_and_kwargs_exception_thrown = False -except: +except Exception: varargs_and_kwargs_exception_thrown = True # test throwing an exception diff --git a/python/ray/tune/trial.py b/python/ray/tune/trial.py index f77a77b9e..01d365270 100644 --- a/python/ray/tune/trial.py +++ b/python/ray/tune/trial.py @@ -98,7 +98,7 @@ class Trial(object): self.agent.stop.remote() self.agent.__ray_terminate__.remote( self.agent._ray_actor_id.id()) - except: + except Exception: print("Error stopping agent:", traceback.format_exc()) self.status = Trial.ERROR finally: @@ -198,7 +198,7 @@ class Trial(object): else: try: ray.get(self.agent.restore.remote(path)) - except: + except Exception: print("Error restoring agent:", traceback.format_exc()) self.status = Trial.ERROR diff --git a/python/ray/tune/trial_runner.py b/python/ray/tune/trial_runner.py index 361d97392..a7672c7ad 100644 --- a/python/ray/tune/trial_runner.py +++ b/python/ray/tune/trial_runner.py @@ -114,14 +114,14 @@ class TrialRunner(object): try: trial.start() self._running[trial.train_remote()] = trial - except: + except Exception: print("Error starting agent, retrying:", traceback.format_exc()) time.sleep(2) trial.stop(error=True) try: trial.start() self._running[trial.train_remote()] = trial - except: + except Exception: print("Error starting agent, abort:", traceback.format_exc()) trial.stop(error=True) # note that we don't return the resources, since they may @@ -143,7 +143,7 @@ class TrialRunner(object): if trial.should_checkpoint(): trial.checkpoint() self._running[trial.train_remote()] = trial - except: + except Exception: print("Error processing event:", traceback.format_exc()) if trial.status == Trial.RUNNING: self._stop_trial(trial, error=True) diff --git a/python/ray/worker.py b/python/ray/worker.py index a2f7f4878..a2a5048a8 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1495,7 +1495,7 @@ def fetch_and_register_remote_function(key, worker=global_worker): try: function = pickle.loads(serialized_function) - except: + except Exception: # If an exception was thrown when the remote function was imported, we # record the traceback and notify the scheduler of the failure. traceback_str = format_error_message(traceback.format_exc()) @@ -1527,7 +1527,7 @@ def fetch_and_execute_function_to_run(key, worker=global_worker): function = pickle.loads(serialized_function) # Run the function. function({"counter": counter, "worker": worker}) - except: + except Exception: # If an exception was thrown when the function was run, we record the # traceback and notify the scheduler of the failure. traceback_str = traceback.format_exc() diff --git a/test/jenkins_tests/multi_node_docker_test.py b/test/jenkins_tests/multi_node_docker_test.py index bf3ba5553..46487d776 100644 --- a/test/jenkins_tests/multi_node_docker_test.py +++ b/test/jenkins_tests/multi_node_docker_test.py @@ -224,13 +224,13 @@ class DockerRunner(object): try: self._stop_node(self.head_container_id) - except: + except Exception: success = False for container_id in self.worker_container_ids: try: self._stop_node(container_id) - except: + except Exception: success = False return success diff --git a/test/runtest.py b/test/runtest.py index ebe7556eb..52ff2e17f 100644 --- a/test/runtest.py +++ b/test/runtest.py @@ -213,8 +213,8 @@ class SerializationTest(unittest.TestCase): pass # Make a list that contains itself. - l = [] - l.append(l) + lst = [] + lst.append(lst) # Make an object that contains itself as a field. a1 = ClassA() a1.field = a1 @@ -227,7 +227,7 @@ class SerializationTest(unittest.TestCase): d1 = {} d1["key"] = d1 # Create a list of recursive objects. - recursive_objects = [l, a1, a2, a3, d1] + recursive_objects = [lst, a1, a2, a3, d1] # Check that exceptions are thrown when we serialize the recursive # objects. @@ -639,15 +639,15 @@ class APITest(unittest.TestCase): return x + 1 @ray.remote - def l(x): + def k2(x): return ray.get(k.remote(x)) @ray.remote def m(x): - return ray.get(l.remote(x)) + return ray.get(k2.remote(x)) self.assertEqual(ray.get(k.remote(1)), 2) - self.assertEqual(ray.get(l.remote(1)), 2) + self.assertEqual(ray.get(k2.remote(1)), 2) self.assertEqual(ray.get(m.remote(1)), 2) def testGetMultiple(self): diff --git a/test/stress_tests.py b/test/stress_tests.py index b59f5e2fa..f6735b776 100644 --- a/test/stress_tests.py +++ b/test/stress_tests.py @@ -108,8 +108,8 @@ class TaskTests(unittest.TestCase): return 1 n = 10 ** 4 # TODO(pcm): replace by 10 ** 5 once this is faster. - l = ray.get([f.remote() for _ in range(n)]) - self.assertEqual(l, n * [1]) + lst = ray.get([f.remote() for _ in range(n)]) + self.assertEqual(lst, n * [1]) self.assertTrue(ray.services.all_processes_alive()) ray.worker.cleanup()