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
RestartSession doesn't run the command after restarting in R3.5.1 #124
Comments
I wasn't able to reproduce this -- the command runs as expected for me. Can you provide any other information / a reproducible example? |
The truth is. The function worked for an entire week, I really don't know what happened and I can't reproduce it. The function works when I tried it on another computer. I am thinking it might be due to some error or crash file. I'll am going to try shutting down the computer and reinstalling R and RStudio to see if it resolves the problem. Is this the first time you have heard of this issue? |
Indeed, this is the first time we've had this issue reported. I can still believe that it can happen, though :-) If you happen to figure out what might've caused this, please let us know! |
The function works again! I tried everything I could think of. I deleted the history of the environment in the main folder and cleared the crash files but it didn't work however shutting the computer down and re-installing did solve the problem. The script will likely take another 2 weeks to run but I have edited the code a bit to print out the progress so I will at least know which part of the code is causing it when it occurs again. The only thing notable was the code stopped because of the lack in memory, although deleting the crash files and quitting RStudio did not solve it. I am wondering how R and RStudio handle code when it crashes. |
Hi Kevin, The problem occurred again and I think I found the problem. It isn't related to the function. Apparently, there is some hidden process that is using all of the memory in the C drive, because there is no more memory, R cannot create a temporary file for the session and the script terminates. When this happens the function no longer works regardless of what I do. I tried to find out if it is the temporary files that are taking up the majority of the space but they were not. I have not been able to detect a virus and system restore is not the cause. Nothing I did seem to reduce the memory usage in C drive. Without reason, about 70GB of space was suddenly freed, however, the function did not work until the computer was restarted. I am not one hundred per cent sure that the disk space issue is the cause of the malfunction but it is my best guess of the issue though I have not been able to ascertain the source of the problem. |
That could explain it. |
Is there a solution to this? I'm trying to iterate/save RAM in same way as @jlcsw (using restartSession with the command to source the same file). Running into the same issue where the process works fine for a while and then abruptly stops. I still can't figure out why it's happening. |
@kevinushey apologies forgot to tag you. Please see my previous comment. |
@sjones29 I did notice that regardless of what I did, the script will terminate after 100 restarts. I am not sure if that is the limit. My solution to the problem was to minimise the number of restarts needed. I don't have a better way unfortunately. It took a lot of experimentation to find something optimal but I manage to get what I need. Hope it helps. |
@jlcsw thanks for the input. Interestingly, my script restarts a variable number of times before I have to manually restart the program; sometimes, I can get significantly over 100 iterations, sometimes only 40 or so, sometimes much less. I may end up trying to optimize the number of restarts as you suggested, even if it eats up more RAM. Haven't gotten any further along in terms of pinpointing the source of the restart interference, but I'll keep looking at it. |
I've just discovered that this function preserves packages and variables in the global environment between restarts, see: #111. Accumulating variables from long running iterative processes is probably what is gobbling user's disk space. This was certainly unexpected to me, and seemingly to the other posters in this thread. Edit: the more I think about this the more certain I am this is a bug. |
Has anyone solved this yet. I used restartSession() in a loop, and it worked for a while. However, out of the blue the function no longer seems to act on the command argument. Here is a simple example to illustrate the issue that is bothering me. Previously running the line restartSession(command="print('Hello')") would restart my session and then print "Hello" to the console. Now, however, running that exact same line of code will restart my session, but it will not print "Hello" any more. |
I cannot reproduce this. Can you add session information? |
For example, when I run: the output is: Restarting R session...
So it restarts session only once, and runs print functions with paste at once... Is there a way to do it correctly? |
I am having similar issues with the command not being executed after restartSession is called. I have created a simple example to demonstrate the issue I am having: Saved the following code to my working directory in a file called restartSessionTest.R:
This normally runs for about ~10 restarts before it falls over giving the following error: A few other observations:
Hope this helps diagnose the problem. Thanks, RStudio Version 1.2.5001
|
Could I just ask if anyone else has been able to replicate this behaviour or is it just me? |
Sorry about pinging this again but was anyone able to figure out a solution here? |
Sorry, but we still haven't been able to reproduce and so don't know what the cause could be. |
I tried running your script and it seemed to run indefinitely, it didn't crash, I had to stop it. |
I needed this restart session command to be able to run a model for a large batch of runs, cleaning out the memory in a comprehensive way between each run. I experienced all of the problems mentioned in earlier comments, The solution I found was to save each scenario command in a separate script file and to source the script within the restart session command. I first tried it like this, but it dodn't work: restartSession(command='source("s718.R")') This does not work because when R restarts it seems to lose the thread of what it was doing and it just stops. So the above script ran the first scenario then stopped. What does seem to work is the following. helloworld <- function(counter) { cat(yellow(paste0("hello world ", counter))) } hw1.R: hw2.R: ... and so on. The key seems to be to call the code that you want R to continue executing within the command string that you provide together with the restartSession command. It's like Russian dolls, or the film "Inception"! The above procedure worked with the simple "helloworld" function, but it does not work when I try to do my model runs with this same approach, for some reason the command passed to restartSession does not get executed. |
I tried restarting the computer as suggested by @jlcsw but unfortunately it still won't work on the second iteration. restartSession(command='source("s718.R")') The above line works. s718.R: The model runs, the R session restarts, but the command 'source("s719.R")' is not executed. I don't know what to do, other than perhaps calling R from a Windows batch file instead of from RStudio. Any help would be much appreciated. |
@alexmitrani: I'm not sure what the issue with the See a toy example below:
EDIT: This doesn't wait before starting the new job, so you still need to build in a check to see if the previous job finished before the new session is started. Should be doable though. |
This is helpful, thanks very much. |
I had this same problem. I was finally able to get the command to run the script after restart by clicking the broom icon above the environments pane and sweeping away everything in the global environment. Something there might have been blocking it, but I don't know why. |
Hi,
I am using restartSession to deal with the problem of insufficient memory and need to clear the memory after each for loop iteration. I have written a code with the intention that a for loop will continue after restarting the R session.
I am grateful for the function restartSession as it allowed my code to run correctly for a week straight before memory became a problem again.
Part of how I do this is to get the restartSession function to source the same script again. This worked for a while but now it does not work anymore. I tried running a simple print('Hello') and '1+1' as the command to run after restarting but there was no output after r restarted.
The actual code which I ran previously is simple.
restartSession(command = "source(path)")
The path is correct because if I copy out the source(path) it runs in the console correctly.
I appreciate any help to troubleshooting the problem.
The text was updated successfully, but these errors were encountered: