Skip to content

Detach thread context during long-running operations#39

Open
cottsay wants to merge 1 commit intomainfrom
cottsay/free-thread
Open

Detach thread context during long-running operations#39
cottsay wants to merge 1 commit intomainfrom
cottsay/free-thread

Conversation

@cottsay
Copy link
Copy Markdown
Member

@cottsay cottsay commented Apr 6, 2026

The underlying Assuan calls are not thread safe and we can't perform multiple operations on the same Assuan context simultaneously. Additionally, the possibility of code calling into this extension from multiple threads necessiatates data race protection mechanisms.

After introducing the necessary protections, I'm moderately confident that this package is now compatible with "free-threaded" Python interpreters as well, so we might as well declare so.

The underlying Assuan calls are not thread safe and we can't perform
multiple operations on the same Assuan context simultaneously.
Additionally, the possibility of code calling into this extension from
multiple threads necessiatates data race protection mechanisms.

After introducing the necessary protections, I'm moderately confident
that this package is now compatible with "free-threaded" Python
interpreters as well, so we might as well declare so.
@cottsay cottsay self-assigned this Apr 6, 2026
@cottsay cottsay added the enhancement New feature or request label Apr 6, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.92958% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.00%. Comparing base (955efe9) to head (9e1ffe2).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/python/server.c 58.69% 14 Missing and 5 partials ⚠️
src/python/client.c 48.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   48.97%   49.00%   +0.02%     
==========================================
  Files          20       20              
  Lines        2638     2704      +66     
  Branches      538      543       +5     
==========================================
+ Hits         1292     1325      +33     
- Misses       1039     1063      +24     
- Partials      307      316       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/python/client.c
rc = assuan_socket_connect(self->ctx, sockpath, ASSUAN_INVALID_PID, 0);
g_free(sockpath);
if (rc) {
assuan_release(self->ctx);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assuan_release(self->ctx);
assuan_release(self->ctx);
self->ctx = NULL;

Comment thread src/python/server.c

if (NULL != self->thread) {
g_thread_ref(self->thread);
g_thread_join(self->thread);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/python/server.c

Py_BEGIN_ALLOW_THREADS

g_rw_lock_writer_lock(&self->lock);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a deadlock here? I don't see the unlock call before the Py_END_ALLOW_THREADS.

Comment thread src/python/server.c

g_rw_lock_reader_unlock(&self->lock);

g_rw_lock_writer_lock(&self->lock);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this also need to check in serer if active like the check above for the reader_lock?

Comment thread src/python/server.c
Py_RETURN_NONE;
}

self->sentinel = 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this write operation needs to be under the writer lock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants