light-scattering-io / caqtus

Package that provides tools to control an experiment
MIT License
0 stars 0 forks source link

Make shot scheduling return a promise #8

Open light-scattering-io opened 4 months ago

light-scattering-io commented 4 months ago

It would be useful when scheduling a shot to run to have some way to know when the shot has completed and has been saved.

This would make it possible to have efficient feedback based iteration of the sequence parameters.

light-scattering-io commented 4 months ago

Two options for this:

  1. Manage running shots in a different thread, so that we'd schedule from the main thread and get back a future that can be waited on until the shot has run in the runner thread.
  2. Use two asyncio tasks in the same thread, one to schedule shots and one to execute them. The scheduling function could just return some awaitable that can be gathered for several shots.

Threading option has the advantage of hiding async/await, but need to be careful if an error ocurres while running the sequence to force the main thread to stop.

Asyncio is is maybe easier since any error while running the sequence could just propagate to cancel the scheduling task transparently. Issue is that both sequence managing and shot scheduling become async.