{"action":"opened","issue":{"url":"https://api.github.com/repos/jbytecode/rcaller/issues/15","repository_url":"https://api.github.com/repos/jbytecode/rcaller","labels_url":"https://api.github.com/repos/jbytecode/rcaller/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/jbytecode/rcaller/issues/15/comments","events_url":"https://api.github.com/repos/jbytecode/rcaller/issues/15/events","html_url":"https://github.com/jbytecode/rcaller/issues/15","id":182983273,"number":15,"title":"Restore Thread interrupt flag after wait","user":{"login":"fbastian","id":3355124,"avatar_url":"https://avatars.githubusercontent.com/u/3355124?v=3","gravatar_id":"","url":"https://api.github.com/users/fbastian","html_url":"https://github.com/fbastian","followers_url":"https://api.github.com/users/fbastian/followers","following_url":"https://api.github.com/users/fbastian/following{/other_user}","gists_url":"https://api.github.com/users/fbastian/gists{/gist_id}","starred_url":"https://api.github.com/users/fbastian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbastian/subscriptions","organizations_url":"https://api.github.com/users/fbastian/orgs","repos_url":"https://api.github.com/users/fbastian/repos","events_url":"https://api.github.com/users/fbastian/events{/privacy}","received_events_url":"https://api.github.com/users/fbastian/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-14T07:40:07Z","updated_at":"2016-10-14T07:40:07Z","closed_at":null,"body":"rcaller code makes the Thread to wait/sleep at some points (which is fine). The problem is that, if the Thread was interrupted, these methods throw an `InterruptedException`, which is caught and rethrown by rcaller without restoring the interrupted thread flag.\r\n\r\nExample in rcaller 2.8: https://github.com/jbytecode/rcaller/blob/c586cb7c74d2e570d6b3ef242c8f3c1561cac49d/RCaller/src/main/java/com/github/rcaller/rstuff/RCaller.java\r\n\r\nThe method `runRCode` uses the method `Process.waitFor`, which throws an `InterruptedException` if the Thread was interrupted, and reinit the interrupted flag of the Thread. A good practice is to catch the `InterruptedException` and to restore the interrupted flag. For instance: \r\n\r\n```\r\ntry {\r\n    //this Process object is local to this method. Do not use the public one.\r\n    process = exec(RscriptExecutable + \" \" + rSourceFile.toString());\r\n    startStreamConsumers(process);\r\n    returnCode = process.waitFor();\r\n} catch (Exception e) {\r\n    if (e instanceof InterruptedException) {\r\n        //restore the interrupt flag so that applications don't loose this information\r\n        Thread.currentThread().interrupt();\r\n    }\r\n    throw new ExecutionException(\"Can not run \" + RscriptExecutable + \". Reason: \" + e.toString());\r\n}\r\n```"}}
{"actor":{"display_login":"fbastian"}}