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

Can not access YDoc object created in another thread #113

Open
trungleduc opened this issue Feb 2, 2023 · 2 comments
Open

Can not access YDoc object created in another thread #113

trungleduc opened this issue Feb 2, 2023 · 2 comments

Comments

@trungleduc
Copy link

Hi, I'm having an issue while accessing a YDoc created from another thread. This is the reproduction code and the error message.

import y_py as Y
import threading, queue
q = queue.Queue()
def create_doc(q):
    a = Y.YDoc()
    q.put(a)
thread = threading.Thread(target=create_doc, args=(q,))
thread.start()
thread.join()
doc = q.get()
doc.get_array('foo')
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `ThreadId(1)`,
 right: `ThreadId(4)`: y_py::y_doc::YDoc is unsendable, but sent to another thread!', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.16.6/src/impl_/pyclass.rs:853:9
---------------------------------------------------------------------------
PanicException                            Traceback (most recent call last)
Cell In[15], line 11
      9 thread.join()
     10 doc = q.get()
---> 11 doc.get_array('foo')

PanicException: assertion failed: `(left == right)`
  left: `ThreadId(1)`,
 right: `ThreadId(4)`: y_py::y_doc::YDoc is unsendable, but sent to another thread!
@trungleduc
Copy link
Author

trungleduc commented Feb 2, 2023

CC @Horusiath @davidbrochart

@Waidhoferj
Copy link
Collaborator

Currently objects in ypy do not implement the Send trait. This is because some of the internals of the yrs Doc type (for the version we use) do not implement Send. In short, you cannot access or pass ypy types between threads. To get around this, you could pass messages between threads using a channel or queue and then integrate those messages into the doc on each thread.

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