-
Notifications
You must be signed in to change notification settings - Fork 92
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
Some R commands are skipped when executing multiple commands after each other #4068
Comments
Can you please paste the code that you ran in as text so it is easy for us to try? |
The screenshot was from a script with my own data, but here is the same code with an example dataset, which also behaves funky: library(tidyverse)
library(phyloseq)
library(decontam)
data(GlobalPatterns)
sample_data(GlobalPatterns)
#' ### Remove contamination
#' #### Visualize library sizes of samples and negative controls
decontam <- as.data.frame(sample_data(GlobalPatterns))
decontam
decontam$LibrarySize <- sample_sums(GlobalPatterns)
decontam <- decontam[order(decontam$LibrarySize),]
decontam$Index <- seq(nrow(decontam))
ggplot(data=decontam, aes(x=Index, y=LibrarySize, color=SampleType)) +
geom_point()+
ggtitle("Library sizes")
ggplot(data=decontam, aes(y="libraries", x=LibrarySize, color=SampleType)) +
geom_jitter(height = .01)+
scale_x_log10()+
ggtitle("Library sizes")
#' #### Detect contaminants
sample_data(GlobalPatterns)$is.neg <- sample_data(GlobalPatterns)$SampleType == "Mock"
sample_data(GlobalPatterns)$is.neg
contamdf.prev <- decontam::isContaminant(GlobalPatterns, method="prevalence", neg="is.neg")
#' **Number of contaminating contigs:**
table(contamdf.prev$contaminant)
contaminants <- rownames(contamdf.prev[contamdf.prev$contaminant==T,]) FYI, first selecting all code that needs to be run and then Cmd+Enter does not give any issues. |
Okay I was able to reproduce. It does look like if you hit library(tidyverse)
library(phyloseq)
library(decontam)
x <- 1
y <- x
z <- y
a <- z Note that I am mashing Screen.Recording.2024-07-18.at.10.40.44.AM.mov |
That's exactly what I'm seeing. I would say that if there is code that runs longer than a few seconds, a "normal" speed of |
I believe this is also coming up for folks when they do something like "Run Above" in a Quarto doc: #4104 |
Another example with "Run above" in a Quarto document: #4231 |
I've got a pretty good idea of what the problem is here, but I could use some advice on the best way to solve this kind of thing. I think the crux of the issue is this positron/src/vs/workbench/services/positronConsole/browser/positronConsoleService.ts Line 1950 in 5c0e593
Imagine that we have a library(tidyverse)
library(phyloseq)
library(decontam)
x <- 1
y <- x
z <- y
positron/src/vs/workbench/services/positronConsole/browser/positronConsoleService.ts Lines 1856 to 1880 in 5c0e593
positron/src/vs/workbench/services/positronConsole/browser/positronConsoleService.ts Lines 1973 to 1982 in 5c0e593
This theory is supported by some console logs, which added logs right before and after that |
…g it (#4257) Addresses #4068 Joint work with @lionel- #4068 (comment) is a detailed account of the problem that this PR addresses, so definitely give that a close read before trying to understand this. The reproducible example that is now fixed is #4068 (comment) The main challenge to deal with is the fact that `await this.session.isCodeFragmentComplete(codeFragment)` is async and is called in a loop inside `processPendingInput()`, allowing the "state of the world", particularly `this._runtimeItemPendingInput`, to change out from under us while we are finding a complete code fragment. There are a few key changes in this PR - We introduce a global `_pendingInputState` to ensure that we cannot re-enter `processPendingInput()` while we are already processing input - If `'Idle'`, we aren't processing any input - If `'Processing'`, we are processing input and cannot call `processPendingInput()` again - If `'Interrupted'`, this is a signal that can happen while we are `'Processing'` inside `processPendingInput()` that we should bail out and stop trying to processing any pending input. - We no longer set `this._runtimeItemPendingInput = undefined;` in `processPendingInput()` before all of the `await isCodeFragmentComplete()` calls. This was particularly bad because at the `await` point we could loop back around into `addPendingInput()` and create an entirely new `this._runtimeItemPendingInput` because it looked like one didn't exist at all! - We pay _very_ careful attention in `processPendingInput()` to ensure that we use either `this._runtimeItemPendingInput.code` or `pendingInputLines`, both of which are guaranteed to always reflect the current state of the world after the `await isCodeFragmentComplete()` calls. Previously, the local variable version of `pendingInputLines` had a strong chance to be outdated after the `await`s. --- This might be a case where it would be useful to write a test that tries to rapidly send some code to the console. If we can come up with a failing test on main (even an intermittent failure would be fine), then we can use that as a test case for this because if that _ever_ fails after this PR then something is wrong. This is the absolute simplest case I can come up with where mashing `Cmd + Enter` on each line _really really fast_ will sometimes trigger the issue on `main`, so that is what I'd try and create a test against. ```r Sys.sleep(.5) print("hi there") Sys.sleep(.5) x <- 1 y <- x z <- y a <- z ```
Verified Fixed
Test scenario(s)Unable to repro manually after many tries. Was able to repro manually with previous release: library(tidyverse) x <- 1 Link(s) to TestRail test cases run or created: |
Positron Version:
Positron Version: 2024.07.0 (Universal) build 67
Code - OSS Version: 1.91.0
Commit: 58e22e1
Date: 2024-07-18T04:44:17.582Z
Electron: 29.4.0
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin x64 23.5.0
Steps to reproduce the issue:
Running multiple commands after each other with Cmd + Enter from an Rscript (without waiting for them to finish), skips the execution of some commands, giving errors downstream. It sometimes even seems that multiple commands are running at the same time.
In the screenshot below you can see the order in which I executed the commands (script) and the output of the console showing which commands ran (white) and which didn't (grey).
What did you expect to happen?
I expected a similar behaviour as Rstudio where you can execute commands from an Rscript, while another command is still running, that are put into a "queue" and executed in order.
Were there any error messages in the Output panel or Developer Tools console?
No
The text was updated successfully, but these errors were encountered: