diff --git a/tangostationcontrol/tangostationcontrol/beam/delays.py b/tangostationcontrol/tangostationcontrol/beam/delays.py index cff779d4aad3d2c669d656a77e57ba1739790283..e50348695d16ceecc3595ae2d041d95af7f9d618 100644 --- a/tangostationcontrol/tangostationcontrol/beam/delays.py +++ b/tangostationcontrol/tangostationcontrol/beam/delays.py @@ -3,6 +3,7 @@ import datetime from functools import lru_cache +import threading from typing import TypedDict import casacore.measures @@ -28,6 +29,9 @@ The measures # Where to store the measures table sets IERS_ROOTDIR = "/opt/IERS" +# Compute lock to prevent thrashing when multithreading +compute_lock = threading.Lock() + def get_IERS_timestamp() -> datetime.datetime: """Return the date of the currently installed IERS tables.""" @@ -200,17 +204,18 @@ class Delays: Returns delays[antenna][direction].""" - # obtain the direction vector for each pointing - direction_vectors = self.get_direction_vector_bulk(pointings) + with compute_lock: + # obtain the direction vector for each pointing + direction_vectors = self.get_direction_vector_bulk(pointings) - # compute the corresponding delays for all directions - def get_delay_all_directions(relative_itrf): - # Dot product between relative position and angle vector determines - # distance. Divide by speed of light to obtain delay. - return numpy.inner(relative_itrf, direction_vectors) / 299792458.0 + # compute the corresponding delays for all directions + def get_delay_all_directions(relative_itrf): + # Dot product between relative position and angle vector determines + # distance. Divide by speed of light to obtain delay. + return numpy.inner(relative_itrf, direction_vectors) / 299792458.0 - delays = numpy.apply_along_axis( - get_delay_all_directions, 1, antenna_relative_itrfs - ) + delays = numpy.apply_along_axis( + get_delay_all_directions, 1, antenna_relative_itrfs + ) - return delays + return delays