OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
117 stars 105 forks source link

Automatic DSDL compilation should lock the directory when compilation is in progress #335

Open pavel-kirienko opened 2 months ago

pavel-kirienko commented 2 months ago

This is to properly support the common scenario when multiple scripts are launched concurrently and both attempt to compile the same namespace, which is a common occurrence with orchestration.

I propose roughly the following algorithm (may require refinement):

  1. Attempt to create a lockfile in the compilation output directory (usually ~/.pycyphal) named after the namespace we're attempting to compile (e.g., uavcan.lock).

  2. If the previous succeeded, proceed to compile the namespace, then remove the lockfile. Done.

  3. On failure to lock the namespace, sleep for a second and check if it's still there.

    • If the lock is gone, attempt importing the namespace again; on success, assume the namespace has been compiled by another process. On import error, assume the namespace requires recompilation and proceed to step 1.
    • If the lock is still there, continue waiting.

Suggestions welcome.