How do I enable print from only one Ray process in Python?

Viewed 439

I am running a recurrent neural network using Tensorflow, and I am varying several of the network parameters in nested loops. Tensorflow has a progress bar, which is nice, but the print is a total mess when the code is parallelised with Ray. Is it possible to suppress the amount of prints by only letting a single process print, or anything equivalent?

1 Answers

I'm speculating a bit about how you're using Ray and what you're trying to do, but this is an example that creates 3 actors and prints from only one of them.

import ray

ray.init()

@ray.remote
class Foo:
    def __init__(self, print):
        self.print = print

    def run(self):
        for i in range(100):
            # do work
            if self.print:
                print('step ', i)

foo1 = Foo.remote(True)
foo2 = Foo.remote(False)
foo3 = Foo.remote(False)
foos = [foo1, foo2, foo3]

ray.get([foo.run.remote() for foo in foos])
Related