mirror of
https://github.com/wassname/ray.git
synced 2026-07-08 09:51:03 +08:00
Improved KeyboardInterrupt Exception Handling (#5237)
This commit is contained in:
+11
-2
@@ -12,6 +12,7 @@ import json
|
||||
import logging
|
||||
import numpy as np
|
||||
import os
|
||||
import redis
|
||||
import signal
|
||||
from six.moves import queue
|
||||
import sys
|
||||
@@ -1520,8 +1521,12 @@ def custom_excepthook(type, value, tb):
|
||||
# If this is a driver, push the exception to redis.
|
||||
if global_worker.mode == SCRIPT_MODE:
|
||||
error_message = "".join(traceback.format_tb(tb))
|
||||
global_worker.redis_client.hmset(b"Drivers:" + global_worker.worker_id,
|
||||
{"exception": error_message})
|
||||
try:
|
||||
global_worker.redis_client.hmset(
|
||||
b"Drivers:" + global_worker.worker_id,
|
||||
{"exception": error_message})
|
||||
except (ConnectionRefusedError, redis.exceptions.ConnectionError):
|
||||
logger.warning("Could not push exception to redis.")
|
||||
# Call the normal excepthook.
|
||||
normal_excepthook(type, value, tb)
|
||||
|
||||
@@ -1583,6 +1588,8 @@ def print_logs(redis_client, threads_stopped):
|
||||
"The driver may not be able to keep up with the "
|
||||
"stdout/stderr of the workers. To avoid forwarding logs "
|
||||
"to the driver, use 'ray.init(log_to_driver=False)'.")
|
||||
except (OSError, redis.exceptions.ConnectionError) as e:
|
||||
logger.error("print_logs: {}".format(e))
|
||||
finally:
|
||||
# Close the pubsub client to avoid leaking file descriptors.
|
||||
pubsub_client.close()
|
||||
@@ -1681,6 +1688,8 @@ def listen_error_messages_raylet(worker, task_error_queue, threads_stopped):
|
||||
task_error_queue.put((error_message, time.time()))
|
||||
else:
|
||||
logger.error(error_message)
|
||||
except (OSError, redis.exceptions.ConnectionError) as e:
|
||||
logger.error("listen_error_messages_raylet: {}".format(e))
|
||||
finally:
|
||||
# Close the pubsub client to avoid leaking file descriptors.
|
||||
worker.error_message_pubsub_client.close()
|
||||
|
||||
Reference in New Issue
Block a user