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

Document how to handle cancellation #314

Open
yutannihilation opened this issue Oct 22, 2024 · 7 comments
Open

Document how to handle cancellation #314

yutannihilation opened this issue Oct 22, 2024 · 7 comments

Comments

@yutannihilation
Copy link
Owner

yutannihilation commented Oct 22, 2024

cf.

@yutannihilation
Copy link
Owner Author

WRE suggests R_CheckUserInterrupt(), but it seems duckdb-r doesn't use it for some reason, which I don't figure out yet. But it seems it's just use csignal.

https://cran.rstudio.com/doc/manuals/r-devel/R-exts.html#Allowing-interrupts

@yutannihilation
Copy link
Owner Author

@eitsupi
Copy link
Contributor

eitsupi commented Oct 22, 2024

This is very useful for me.

The current polars package implements the following, which I believe is not ideal.
eitsupi/neo-r-polars#23 (comment)
https://github.com/pola-rs/r-polars/blob/a7b064265f56ece53358955979f929b2cc055c63/src/rust/src/utils/extendr_concurrent.rs#L234-L250

@yutannihilation
Copy link
Owner Author

Oh, the current implementation looks very hacky...

I thought we can learn from Python Polars' implementation, but it seems they have their own difficulties...

pola-rs/polars#2687
https://pyo3.rs/v0.22.5/faq#ctrl-c-doesnt-do-anything-while-my-rust-code-is-executing

@yutannihilation
Copy link
Owner Author

I think this is the naive translation to Rust, but this doesn't work except for the first Ctrl+C...

https://github.com/yutannihilation/cancel.test.savvy/blob/main/src/rust/src/lib.rs

@yutannihilation
Copy link
Owner Author

Some more findings:

  • It seems this is something related to the interaction with Positron. If I do the same thing on the bare R session on a terminal, Ctrl+C works as expected
  • Calling eval_parse_text("Sys.sleep(0)")? on every loop is a workaround.
  • However, considering krlmlr/cancel.test works without such a workaround, probably I'm missing some point
    • To be clear, krlmlr/cancel.test uses cpp11::message, which evaluates message call, but it works fine without it

@yutannihilation
Copy link
Owner Author

Calling eval_parse_text("Sys.sleep(0)")? on every loop is a workaround.

Other than Sys.sleep, message() and warning() works. However, most functions don't seem to work.

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