From 4e702a926a54b3544fbc2632198fbc473bfc917d Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Thu, 2 Jan 2025 08:33:48 -0500 Subject: [PATCH] Replica is not Send (#25) The TC type `Replica` is legitimately not `Send`, because it embeds a `Storge` implementation and that implementation may not be `Send`. In fact, the SQLite implementation is not -- SQLite is single-threaded. I think this is a reasonable restriction for the library for the moment. If there is at some point a need to use a Replica from multiple threads, then we can consider ways to lift this restriction safely. --- src/replica.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/replica.rs b/src/replica.rs index 4d38ca5..0e8c4dd 100644 --- a/src/replica.rs +++ b/src/replica.rs @@ -6,12 +6,14 @@ use crate::{DependencyMap, Operations, Task, WorkingSet}; use pyo3::prelude::*; use taskchampion::{Replica as TCReplica, ServerConfig, StorageConfig, Uuid}; -#[pyclass] +#[pyclass(unsendable)] /// A replica represents an instance of a user's task data, providing an easy interface /// for querying and modifying that data. +/// +/// A replica can only be used in the thread in which it was created. Use from any other +/// thread will panic. pub struct Replica(TCReplica); -unsafe impl Send for Replica {} #[pymethods] impl Replica { #[staticmethod]