-
Notifications
You must be signed in to change notification settings - Fork 21
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
Compatibility with httpuv #43
Comments
The reason this happens is because the Chromote object creates its own event loop, which is a "child" of the global event loop. With the later package, there is a global event loop, and it is possible to create event loops which are children of the global loop. (And similarly, it is possible to create children of children.) When an event loop is run, it also runs its children. However, when a child event loop is run, it does not run the parent. (Also, the global loop runs automatically when the R console is idle.) The purpose of the child event loops is so that asynchronous code can be run "synchronously", without accidentally affecting other asynchronous code. In Chromote, the Here's an example to illustrate why child loops are important. Shiny apps work by using the global event loop: somewhere in the code it calls observe({
b <- ChromoteSession$new()
b$Page$navigate(url = input$url)
b$screenshot()
b$close()
}) This observer is triggered by an incoming message that says that Chromote avoids this problem by using child event loop. When a child event loop is run, it does not cause the global loop to run, and so the observer above is safe. The problem you have here is that the httpuv application uses the global loop, but when a Chromote command is issued with As for working around the problem, I tried starting the httpuv app with the Chromote object's child loop, using the library(chromote)
library(servr)
b <- ChromoteSession$new()
b$view()
# launch a httpuv server
later::with_loop(b$get_child_loop(), {
svr <- httd(file.path(R.home("doc"), "manual"))
})
faq_url <- paste(svr$url, "R-FAQ.html", sep = "/")
browseURL(faq_url)
# Works
b$Page$navigate(url = faq_url, wait_ = FALSE)
# Still hangs with wait_ = TRUE
b$Page$navigate(url = faq_url) Note that for httpuv's unit tests, we have a similar issue, where use curl to fetch data from the httpuv application. If we used the regular, blocking function It is called indirectly using I don't have a good workaround at the moment, but that does not mean that it's impossible to make work. |
Thanks for the explanations. I have already noticed that servr only uses the global events loop. Maybe this issue is mostly on the httpuv side. For now, here is my workaround: library(chromote)
library(servr)
b <- ChromoteSession$new()
b$view()
b$parent$debug_messages(TRUE)
# launch a httpuv server
svr <- httd(file.path(R.home("doc"), "manual"))
faq_url <- paste(svr$url, "R-FAQ.html", sep = "/")
browseURL(faq_url)
{
p <- b$Page$navigate(url = faq_url, wait_ = FALSE)
chromote:::synchronize(p, loop = later::global_loop())
} |
My R session hangs when I try to open a local web page served by a httpuv server with
wait_=TRUE
. It seems that the httpuv loop does not run (this may be related to rstudio/httpuv#250, feel free to close this issue).Here is an example:
The text was updated successfully, but these errors were encountered: