diff --git a/working_dir_error_replication/reader.py b/working_dir_error_replication/reader.py new file mode 100644 index 000000000..b81857ade --- /dev/null +++ b/working_dir_error_replication/reader.py @@ -0,0 +1,29 @@ +import asyncio +import time +from cognee.infrastructure.databases.graph.kuzu.adapter import KuzuAdapter + +# This will create the test.db if it doesn't exist + + +async def main(): + print("Reader: Waiting 2 seconds...") + + time.sleep(5) + adapter = KuzuAdapter("test.db") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + + print(f"Reader: Found {result[0][0]} nodes") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + print(f"Reader: Found {result[0][0]} nodes") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + print(f"Reader: Found {result[0][0]} nodes") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + print(f"Reader: Found {result[0][0]} nodes") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + print(f"Reader: Found {result} nodes") + result = await adapter.query("MATCH (n:Node) RETURN COUNT(n)") + print(f"Reader: Found {result[0][0]} nodes") + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/working_dir_error_replication/run_subprocess_test.py b/working_dir_error_replication/run_subprocess_test.py new file mode 100644 index 000000000..955e0f3fe --- /dev/null +++ b/working_dir_error_replication/run_subprocess_test.py @@ -0,0 +1,29 @@ +""" +Run writer and reader in separate subprocesses to test Kuzu locks. +""" + +import subprocess +import time +import os + +def main(): + print("=== Kuzu Subprocess Lock Test ===") + print("Starting writer and reader in separate subprocesses...") + print("Writer will hold the database lock, reader should block or fail\n") + + start_time = time.time() + + # Start writer subprocess + writer_process = subprocess.Popen([os.sys.executable, "writer.py"]) + + reader_process = subprocess.Popen([os.sys.executable, "reader.py"]) + + # Wait for both processes to complete + writer_process.wait() + reader_process.wait() + + total_time = time.time() - start_time + print(f"\nTotal execution time: {total_time:.2f}s") + +if __name__ == "__main__": + main() diff --git a/working_dir_error_replication/writer.py b/working_dir_error_replication/writer.py new file mode 100644 index 000000000..2e0ce1728 --- /dev/null +++ b/working_dir_error_replication/writer.py @@ -0,0 +1,31 @@ +import asyncio +from uuid import uuid4 +from cognee.infrastructure.databases.graph.kuzu.adapter import KuzuAdapter +import time +import uuid +from cognee.modules.chunking.models.DocumentChunk import DocumentChunk +from cognee.modules.data.processing.document_types import PdfDocument + + +def create_node(name): + document = PdfDocument( + id=uuid.uuid4(), + name=name, + raw_data_location=name, + external_metadata="", + mime_type="", + ) + return document + +async def main(): + adapter = KuzuAdapter("test.db") + print("Writer: Starting...") + nodes = [create_node(f"Node{i}") for i in range(100)] + await adapter.add_nodes(nodes) + + print("writer finished...") + + time.sleep(100) + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file