Skip to content

Instantly share code, notes, and snippets.

@m4nuC
Created October 30, 2025 20:54
Show Gist options
  • Save m4nuC/5f8cc7cb65cf51197084d6809ff2cce2 to your computer and use it in GitHub Desktop.
Save m4nuC/5f8cc7cb65cf51197084d6809ff2cce2 to your computer and use it in GitHub Desktop.
Traceback (most recent call last):
File "/tmp/ipykernel_223/219424108.py", line 111, in process_all_document_embeddings_parallel
results = await asyncio.gather(*tasks)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ipykernel_223/219424108.py", line 39, in process_document_batch
await update_document_embeddings(conn, updates)
File "/tmp/ipykernel_223/2652621049.py", line 114, in update_document_embeddings
await conn.executemany(query, formatted_updates)
File "/usr/local/lib/python3.12/dist-packages/asyncpg/connection.py", line 390, in executemany
return await self._executemany(command, args, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/asyncpg/connection.py", line 1988, in _executemany
result, _ = await self._do_execute(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/asyncpg/connection.py", line 2024, in _do_execute
result = await executor(stmt, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg/protocol/protocol.pyx", line 268, in bind_execute_many
asyncpg.exceptions.DeadlockDetectedError: deadlock detected
DETAIL: Process 671958 waits for ExclusiveLock on advisory lock [296936,0,2700260,1]; blocked by process 672029.
Process 672029 waits for ExclusiveLock on advisory lock [296936,0,2763643,1]; blocked by process 671958.
HINT: See server log for query details.
Batch 10: 100 docs, 287 queries ✓
Batch 9: 100 docs, 293 queries ✓
---------------------------------------------------------------------------
DeadlockDetectedError Traceback (most recent call last)
Cell In[11], line 1
----> 1 await process_all_document_embeddings_parallel(start_offset=668100)
Cell In[10], line 111, in process_all_document_embeddings_parallel(start_offset)
109 # Execute all batches in parallel
110 print(f"\nRound {batch_round}: Processing {len(tasks)} batches in parallel...")
--> 111 results = await asyncio.gather(*tasks)
113 # Update progress
114 round_processed = sum(results)
Cell In[10], line 39, in process_document_batch(pool, offset, batch_size, batch_id)
33 updates = [
34 (doc['document_id'], doc['created_at'], emb.tolist())
35 for doc, emb in zip(documents, doc_embeddings)
36 ]
38 # Update database
---> 39 await update_document_embeddings(conn, updates)
41 print(f" Batch {batch_id}: {len(documents)} docs, {total_queries} queries ✓")
43 return len(documents)
Cell In[8], line 114, in update_document_embeddings(conn, updates)
111 vector_str = '[' + ','.join(str(float(x)) for x in embedding) + ']'
112 formatted_updates.append((vector_str, doc_id, created_at))
--> 114 await conn.executemany(query, formatted_updates)
File /usr/local/lib/python3.12/dist-packages/asyncpg/connection.py:390, in Connection.executemany(self, command, args, timeout)
362 """Execute an SQL *command* for each sequence of arguments in *args*.
363
364 Example:
(...) 387 ``executemany()`` was called in a transaction.
388 """
389 self._check_open()
--> 390 return await self._executemany(command, args, timeout)
File /usr/local/lib/python3.12/dist-packages/asyncpg/connection.py:1988, in Connection._executemany(self, query, args, timeout, return_rows, record_class)
1986 with self._stmt_exclusive_section:
1987 with self._time_and_log(query, args, timeout):
-> 1988 result, _ = await self._do_execute(
1989 query, executor, timeout, record_class=record_class
1990 )
1991 return result
File /usr/local/lib/python3.12/dist-packages/asyncpg/connection.py:2024, in Connection._do_execute(self, query, executor, timeout, retry, ignore_custom_codec, record_class)
2022 try:
2023 if timeout is None:
-> 2024 result = await executor(stmt, None)
2025 else:
2026 try:
File /usr/local/lib/python3.12/dist-packages/asyncpg/protocol/protocol.pyx:268, in bind_execute_many()
DeadlockDetectedError: deadlock detected
DETAIL: Process 671958 waits for ExclusiveLock on advisory lock [296936,0,2700260,1]; blocked by process 672029.
Process 672029 waits for ExclusiveLock on advisory lock [296936,0,2763643,1]; blocked by process 671958.
HINT: See server log for query details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment