python
(ignore_reinit_error=True), RuntimeError: Maybe you called ray.init twice by accident? This error can be suppressed by passing in 'ignore_reinit_error=True' or by calling 'ray.shutdown()' prior to 'ray.init()'.
ignore_reinit_error peut décider d'émettre __error __ lorsque __ray.init () __ est exécuté __ plusieurs fois __.
Le défaut est faux__.
Prenons l'exemple de la programmation suivante.
Exemple 1: Exemple de modification de ignore_reinit_error en __ False </ font> __. Autrement dit, il reste ray.init (num_cpus = 1).
python
import time
import ray
if __name__ == "__main__":
for i in range(2):
ray.init(num_cpus=1)
@ray.remote
def time_function(num):
time.sleep(1)
return num
time.sleep(2)
start_time = time.time()
numbers = ray.get([time_function.remote(i) for i in range(5)])
end_time = time.time()
duration = end_time-start_time
print('numbers = {}, duration = {}'.format(numbers, duration))
#RuntimeError: Maybe you called ray.init twice by accident? This error can be suppressed by passing in 'ignore_reinit_error=True' or by calling 'ray.shutdown()' prior to 'ray.init()'.
Dans l'exemple 1 ci-dessus, ray.init a été exécuté ___2 fois, donc __error __ s'est produit.
Exemple 2: Exemple de modification de ignore_reinit_error en __ True </ font> __. Autrement dit, ray.init (num_cpus = 1, ignore_reinit_error = True).
python
import time
import ray
if __name__ == "__main__":
for i in range(2):
ray.init(num_cpus=1, ignore_reinit_error=True)
@ray.remote
def time_function(num):
time.sleep(1)
return num
time.sleep(2)
start_time = time.time()
numbers = ray.get([time_function.remote(i) for i in range(5)])
end_time = time.time()
duration = end_time-start_time
print('numbers = {}, duration = {}'.format(numbers, duration))
#numbers = [0, 1, 2, 3, 4], duration = 5.047511100769043
Calling ray.init() again after it has already been called.
numbers = [0, 1, 2, 3, 4], duration = 5.015073537826538
Dans l'exemple 2, ray.init a été exécuté ___2 fois, mais aucune erreur __ ne s'est produite __.
Ce qui précède est l'opération de ignore_reinit_error.
Recommended Posts