API documentation for tradingstrategy.transport.cache.wait_other_writers Python function.

wait_other_writers(path, timeout=120)[source]#

Wait other potential writers writing the same file.

  • Work around issues when parallel unit tests and such try to write the same file


import urllib
import tempfile

import pytest
import pandas as pd

def my_cached_test_data_frame() -> pd.DataFrame:

    # Al tests use a cached dataset stored in the /tmp directory
    path = os.path.join(tempfile.gettempdir(), "my_shared_data.parquet")

    with wait_other_writers(path):

        # Read result from the previous writer
        if not path.exists(path):
            # Download and write to cache
            urllib.request.urlretrieve("https://example.com", path)

        return pd.read_parquet(path)
  • path (pathlib.Path | str) – File that is being written

  • timeout

    How many seconds wait to acquire the lock file.

    Default 2 minutes.