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

Hook to use execution context #184

Closed
jnumainville opened this issue Dec 22, 2023 · 0 comments · Fixed by #205
Closed

Hook to use execution context #184

jnumainville opened this issue Dec 22, 2023 · 0 comments · Fixed by #205
Assignees
Labels
deephaven.ui enhancement New feature or request
Milestone

Comments

@jnumainville
Copy link
Collaborator

from Bender on #168:
We probably should make a hook just for submitting tasks with the execution context, similar to how I made the use_render_queue hook for submitting tasks on the render thread.

Could be named use_execution_context

@vbabich vbabich added this to the Backlog milestone Jan 2, 2024
@vbabich vbabich removed the triage label Jan 2, 2024
@vbabich vbabich modified the milestones: Backlog, January 2024 Jan 2, 2024
jnumainville added a commit that referenced this issue Jan 23, 2024
The hook can be used to call code within an execution context

It is a fairly niche hook, but here as an example of it being used to do
a table update on a separate thread

```
import deephaven.ui as ui
import threading
from deephaven.execution_context import get_exec_ctx
from deephaven import agg as agg
import deephaven.pandas as dhpd
import deephaven.plot.express as dx

stocks = dx.data.stocks()

def print_sym(source):
    print(dhpd.to_pandas(source.update(["Symbol = sym"]) \
        .agg_by([agg.avg(cols=["AVG = size"])], by=["Symbol"])))

@ui.component
def exec_ctx_hook(source):

    with_exec_ctx = ui.use_execution_context()
    
    def thread_func():
        #print_sym(source)
        with_exec_ctx(lambda: print_sym(source))

    def start_thread():
        thread = threading.Thread(target=thread_func)
        thread.start()

    ui.use_memo(start_thread, source)

    return None

exec_hook = exec_ctx_hook(stocks)
```

Fixes #184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deephaven.ui enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants