Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR message "already borrowed" when trying to update a map in a callback #154

Open
scenaristeur opened this issue Mar 24, 2024 · 1 comment

Comments

@scenaristeur
Copy link

seems to be similar to #69
I have three maps like a kanban : todos, doing, done and i want a worker to be able to "move" a task from "todos" to "doing" but i've got an "already borrowed" error and i don't know how to deal with it

here is my code

import asyncio
import y_py as Y
from websockets import connect
from ypy_websocket import WebsocketProvider

async def client():
    ydoc = Y.YDoc()
    async with (
        connect("ws://localhost:1234/my-roomname") as websocket,
        WebsocketProvider(ydoc, websocket),
    ):
        def callback(e):
            print("\n-----------")
            print("TODOS",todos)
            print("DOING",doing)
            print("DONE",done)
            #print("\nKEYS",todos.keys())
            #print("\nEVENTS",e.keys)
            for id , task in todos.items():
                print("------1 todo",id, "->", task)
                try:
                    ydoc.transact(lambda txn: todos.pop(txn, id))
                    ydoc.transact(lambda txn: doing.set(txn, id, task))
                except Exception as e:
                    print("ERROR", e)

        todos = ydoc.get_map("todos")
        doing = ydoc.get_map("doing")
        done = ydoc.get_map("done")

        todos.observe(callback)
        doing.observe(callback)
        done.observe(callback)

        await asyncio.Future()  # run forever

asyncio.run(client())

and the log :

-----------
TODOS {'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70': {'created': 1711295273830.0, 'text': 'Bonjour', 'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'id': 'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70'}, '934e1974-69ac-431e-b234-c290b006ca55': {'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'id': '934e1974-69ac-431e-b234-c290b006ca55', 'text': 'Bonjour', 'created': 1711295173598.0}}
DOING {}
DONE {}
------1 todo 934e1974-69ac-431e-b234-c290b006ca55 -> {'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'created': 1711295173598.0, 'text': 'Bonjour', 'id': '934e1974-69ac-431e-b234-c290b006ca55'}
ERROR Already borrowed
------1 todo cb3efbd1-a2cd-48e0-960f-9f1f1247ab70 -> {'created': 1711295273830.0, 'text': 'Bonjour', 'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'id': 'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70'}
ERROR Already borrowed

-----------
TODOS {'934e1974-69ac-431e-b234-c290b006ca55': {'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'text': 'Bonjour', 'created': 1711295173598.0, 'id': '934e1974-69ac-431e-b234-c290b006ca55'}, 'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70': {'id': 'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70', 'text': 'Bonjour', 'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'created': 1711295273830.0}}
DOING {}
DONE {}
------1 todo 934e1974-69ac-431e-b234-c290b006ca55 -> {'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'created': 1711295173598.0, 'id': '934e1974-69ac-431e-b234-c290b006ca55', 'text': 'Bonjour'}
ERROR Already borrowed
------1 todo cb3efbd1-a2cd-48e0-960f-9f1f1247ab70 -> {'id': 'cb3efbd1-a2cd-48e0-960f-9f1f1247ab70', 'created': 1711295273830.0, 'asker': 'c4fbbffd-c97b-4e3c-b769-9a7fc5420fb9', 'text': 'Bonjour'}
ERROR Already borrowed

@scenaristeur scenaristeur changed the title already borrowed trying to update in a callback ERROR message "already borrowed" when trying to update in a callback Mar 24, 2024
@scenaristeur scenaristeur changed the title ERROR message "already borrowed" when trying to update in a callback ERROR message "already borrowed" when trying to update a map in a callback Mar 24, 2024
@davidbrochart
Copy link
Collaborator

Ypy is unmaintained, you may want to look at pycrdt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants