I use the logging module in the main function/process, it works well, but it seems can't work in Actor process/subprocess. How to make it work? In the sample below code, logging.info work in the main process but failed in the worker process. Thanks.
import logging
import ray
@ray.remote
class Worker(object):
...
def train(self):
logging.info("fail print")
...
worker = Worker.remote()
ray.get(worker.train.remote())
logging.info("successful print")
There are a couple things to be careful about.
logger.warning
instead of logger.info
because the Python logging level is set to `warning by default.Here is a working example:
import logging
import ray
logger = logging.getLogger(__name__)
@ray.remote
class Worker(object):
def __init__(self):
self.logger = logging.getLogger(__name__)
def train(self):
self.logger.warning("print from inside worker")
ray.init()
worker = Worker.remote()
ray.get(worker.train.remote())
logger.warning("print from outside worker")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With