labthings / labthings/labthings-fastapi

More flexibility in the global lock

Open
#401 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
lt.ThreadWithInvocationID allows one Action to run code in a background thread, with the ability to cancel it using the existing cancellation mechanism. However, if the global lock is enabled, it's not possible to run an Action, because it won't be able to acquire the global lock (which is already in use by the original Action thread).

Describe the solution you'd like
I'd like the thread that currently holds the global lock to be able to somehow "share" (or bypass) the global lock with selected threads that it has started. Arguably, it could be as simple as lt.ThreadWithInvocationID(target=thing.action, share_global_lock=True).

This probably requires a fair bit of extra code in GlobalLock and will want careful testing. However, I think it can be done safely and sensibly.

Describe alternatives you've considered
I think the best current work-around would inspect the Action descriptor to get the un-wrapped Action function. In many cases, this would mean it doesn't try to acquire the global lock and will work OK. It is very likely to go wrong, though, and quite ugly.

An option to bypass the global lock feels much less safe to me than a mechanism to share the lock.

Additional context
This would be required to make the current version of "flying z stack" work with global lock enabled merge request.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating GlobalLock and ThreadWithInvocationID, then trace how the global lock is acquired by an Action and by threads it starts. Define and test a safe way for selected child threads to share the lock without allowing unrelated Actions to bypass it; the flying z stack merge request provides the usage context.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.