Bug 14730 - tcltk window freezes when interrupting calculations/locator function
Summary: tcltk window freezes when interrupting calculations/locator function
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific (show other bugs)
Version: R 2.14.0
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 major
Assignee: R-core
URL:
: 14563 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-11-13 21:44 UTC by Francois Rousseu
Modified: 2013-08-05 10:06 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois Rousseu 2011-11-13 21:44:54 UTC
I posted this on the R-help mailing list a couple of days ago, but here it might be more relevant. Don't know if it should have been added to other similar bug reports with tcltk.

Using the following code: 
  
library(tcltk) 
win<-tktoplevel() 
ff<-function(){ 
         plot(1:10,1:10) 
         pol<-locator(1) 
         print(pol) 
         } 
button<-tkbutton(win,text="test",command=ff) 
tkpack(button) 
  
makes the win panel stop responding when the plot is closed before choosing a location. Usually, the windows task manager has to be used to close the window (which causes R to be stopped as well) or a message saying that R is not responding is displayed. In fact, the same thing happens (win freezes) when a long computation generated by the tcltk window is stopped through the R console. 
  
library(tcltk) 
library(svMisc) 
win<-tktoplevel() 
n<-10000 
ff<-function(){ 
         for(i in 1:n){progress(i,n)} 
         } 
button<-tkbutton(win,text="test",command=ff) 
tkpack(button) 


I was having the same problem with R 2.13.0 so I upgraded to 2.14.0 but the problem persists. Same thing happens with 32-bit Rgui. I am using windows 7.

> sessionInfo()

R version 2.14.0 (2011-10-31)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252   
[3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_Canada.1252    

attached base packages:
[1] tcltk     stats     graphics  grDevices utils     datasets  methods   base     

> version
               _                            
platform       x86_64-pc-mingw32            
arch           x86_64                       
os             mingw32                      
system         x86_64, mingw32              
status                                      
major          2                            
minor          14.0                         
year           2011                         
month          10                           
day            31                           
svn rev        57496                        
language       R                            
version.string R version 2.14.0 (2011-10-31) 

Francois Rousseu
Comment 1 Francois Rousseu 2011-11-14 03:20:35 UTC
With the locator function, instead of clicking on the graph, I close the graphic window by clicking on the X button. With the long calculation, I use the Gui menu and stop the computation. I just tried with Rgui with MDI and SDI options. I also tried with R 32 bit and with Rterm 64 bit. This is with Windows 7 family premium edition. Also, I tried with my old computer with Windows XP family edition and R 2.14.0 and it is the same. Usually, after closing the graphic without locating a point, the tk window responsiveness really slows down and it is not possible to close it using the X button. Eventually, the delay between the push of the test button on the tk window and the apparition of the graph is so long that the task manager has to be invoked to close the tk window, which also closes R (Windows message Rgui not responding). However, while the tk window is slowed down, Rgui can be used at the prompt normally and it can be closed normally as well. I noticed you used the patched version, but mine is the regular 2.14.0 version. I guess I should upgrade to the patch version?

Francois Rousseu
Comment 2 Duncan Murdoch 2011-11-14 03:54:19 UTC
On 11-11-13 3:44 PM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14730
>
>             Summary: tcltk window freezes when interrupting
>                      calculations/locator function
>             Product: R
>             Version: R 2.14.0
>            Platform: x86_64/x64/amd64 (64-bit)
>          OS/Version: Windows 64-bit
>              Status: NEW
>            Severity: major
>            Priority: P5
>           Component: Windows GUI / Window specific
>          AssignedTo: R-core@R-project.org
>          ReportedBy: francoisrousseu@hotmail.com
>     Estimated Hours: 0.0
>
>
> I posted this on the R-help mailing list a couple of days ago, but here it
> might be more relevant. Don't know if it should have been added to other
> similar bug reports with tcltk.
>
> Using the following code:
>
> library(tcltk)
> win<-tktoplevel()
> ff<-function(){
>           plot(1:10,1:10)
>           pol<-locator(1)
>           print(pol)
>           }
> button<-tkbutton(win,text="test",command=ff)
> tkpack(button)
>
> makes the win panel stop responding when the plot is closed before choosing a
> location. Usually, the windows task manager has to be used to close the window
> (which causes R to be stopped as well) or a message saying that R is not
> responding is displayed. In fact, the same thing happens (win freezes) when a
> long computation generated by the tcltk window is stopped through the R
> console.


I don't see this in 32 bit XP when I try it in 2.14.0 patched. I'll try 
Win64 tomorrow.  But could you be even more specific in your 
description, just in case it's not a 32 bit versus 64 bit difference?

  - Windows version?
  - How did you close the plot?
  - What did you do that wasn't responded to afterwards?
  - Are you using Rterm or Rgui, and if the latter, MDI (little windows 
in one big one) or SDI (all separate windows) mode?


Duncan Murdoch

>
> library(tcltk)
> library(svMisc)
> win<-tktoplevel()
> n<-10000
> ff<-function(){
>           for(i in 1:n){progress(i,n)}
>           }
> button<-tkbutton(win,text="test",command=ff)
> tkpack(button)
>
>
> I was having the same problem with R 2.13.0 so I upgraded to 2.14.0 but the
> problem persists. Same thing happens with 32-bit Rgui. I am using windows 7.
>
>> sessionInfo()
>
> R version 2.14.0 (2011-10-31)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252
> [3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C
> [5] LC_TIME=French_Canada.1252
>
> attached base packages:
> [1] tcltk     stats     graphics  grDevices utils     datasets  methods   base
>
>> version
>                 _
> platform       x86_64-pc-mingw32
> arch           x86_64
> os             mingw32
> system         x86_64, mingw32
> status
> major          2
> minor          14.0
> year           2011
> month          10
> day            31
> svn rev        57496
> language       R
> version.string R version 2.14.0 (2011-10-31)
>
> Francois Rousseu
>



Comment 3 Francois Rousseu 2011-11-15 00:03:46 UTC
Don't know if this is of any help, but tclServiceMode() goes from TRUE to FALSE when the tk window stops responding. Although this may be just an obvious symptom from the problem.

Francois Rousseu
Comment 4 Duncan Murdoch 2011-11-15 04:05:02 UTC
On 11-11-13 9:20 PM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14730
>
> --- Comment #1 from Francois Rousseu<francoisrousseu@hotmail.com>  2011-11-13 21:20:35 EST ---
> With the locator function, instead of clicking on the graph, I close the
> graphic window by clicking on the X button. With the long calculation, I use
> the Gui menu and stop the computation. I just tried with Rgui with MDI and SDI
> options. I also tried with R 32 bit and with Rterm 64 bit. This is with Windows
> 7 family premium edition. Also, I tried with my old computer with Windows XP
> family edition and R 2.14.0 and it is the same. Usually, after closing the
> graphic without locating a point, the tk window responsiveness really slows
> down and it is not possible to close it using the X button. Eventually, the
> delay between the push of the test button on the tk window and the apparition
> of the graph is so long that the task manager has to be invoked to close the tk
> window, which also closes R (Windows message Rgui not responding). However,
> while the tk window is slowed down, Rgui can be used at the prompt normally and
> it can be closed normally as well. I noticed you used the patched version, but
> mine is the regular 2.14.0 version. I guess I should upgrade to the patch
> version?
>
> Francois Rousseu
>


Okay, I can reproduce it now, I didn't understand the problem at first.

This looks like a tcltk problem:  it is not handling the break properly. 
   A simple version that shows it without graphics or another package is

library(tcltk)
win<-tktoplevel()
ff<-function(){
     for (i in 1:10) {
          Sys.sleep(1)
	print(i)
          flush.console()	
      }
}
button<-tkbutton(win,text="test",command=ff)
tkpack(button)

If I hit Esc in the console to break the computation, the tcltk window 
is left unresponsive.

I don't know the tcltk code well enough to see where this is going 
wrong, but I'd guess the problem is arising because of a missing 
"begincontext/endcontext" pair in the C code.

Duncan Murdoch


Comment 5 Thomas Friedrichsmeier 2011-12-14 12:20:34 UTC
*** Bug 14563 has been marked as a duplicate of this bug. ***
Comment 6 Brian Ripley 2011-12-14 15:39:13 UTC
Note that the Tcl/Tk event loop is handled differently on Windows and other OSes, so a problem on Linux is not a duplicate of one on Windows.  That it is handled differently points the finger towards Tcl/Tk if similar issues are seen on disparate platforms.

I'm not going to assign this: no one has volunteered to work on it.
Comment 7 Francois Rousseu 2012-03-01 20:00:09 UTC
Hello

I'm wondering if it is reasonable to hope for a fix to this bug in a not too distant future. My intent here is not to put any pressure or anything as the R Core team probably has a million other things to do. I am just asking because I am working on a package that relies entirely on tcltk windows to build a friendly user interface for users not so familiar with R and the likelihood of crashing the tcltk windows is really high  due to the use of interactive maps and long computations. I am just wondering if it would be a good idea for me to explore and switch to other R methods of creating user interfaces.

Thanks,
Francois Rousseu
Comment 8 Duncan Murdoch 2012-03-02 02:28:54 UTC
On 01/03/2012 2:00 PM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14730
>
> --- Comment #7 from Francois Rousseu<francoisrousseu@hotmail.com>  2012-03-01 14:00:09 EST ---
> Hello
>
> I'm wondering if it is reasonable to hope for a fix to this bug in a not too
> distant future. My intent here is not to put any pressure or anything as the R
> Core team probably has a million other things to do. I am just asking because I
> am working on a package that relies entirely on tcltk windows to build a
> friendly user interface for users not so familiar with R and the likelihood of
> crashing the tcltk windows is really high  due to the use of interactive maps
> and long computations. I am just wondering if it would be a good idea for me to
> explore and switch to other R methods of creating user interfaces.


I don't think it's likely that I'll have a chance to work on this before 
2.15.0 at the end of the month.  If nobody else steps forward, I think 
you'll have to dig in and track it down yourself.

Duncan Murdoch


Comment 9 Francois Rousseu 2012-03-03 14:19:48 UTC
Thank you for your answer M. Murdoch. I would be very happy to help with this, but unfortunately, I know nothing about C and I think that tracking down this problem is way beyond my abilities. And the future doesn't seem too distant either.

Sincerely,
Francois Rousseu
Comment 10 Scott Kostyshak 2013-08-05 10:06:14 UTC
I think I found related behavior (if not, please tell me to open a different bug report if appropriate). I can reproduce the following on Ubuntu 12.04.2 and 13.04 64-bit with R version 3.0.1 and with r63479. There
is no difference if R is patched with the fix for PR#15407 or not,
although without the fix there are more ways to trigger this.

I can reproduce with the following:

1. Open R in gnome-terminal or xterm

2. Run 'library(tcltk)'

3. Run 'trace(tk_select.list, edit = TRUE)'
and put "browser()" at the beginning of the onOK body (e.g. in Vim run
<<:g/onOK/put ='browser()'>>). That is, transform

    onOK <- function() {
        res <- 1L + as.integer(tkcurselection(box))
        cat("res is: ", res)
        ans.select_list <<- choices[res]
        tkgrab.release(dlg)
        tkdestroy(dlg)
    }

to:

    onOK <- function() {
        browser()
        res <- 1L + as.integer(tkcurselection(box))
        cat("res is: ", res)
        ans.select_list <<- choices[res]
        tkgrab.release(dlg)
        tkdestroy(dlg)
    }

4. Run 'install.packages()'

5. Double-click on a package

R becomes unresponsive and I have to kill it.

> sessionInfo()
R Under development (unstable) (2013-08-02 r63479)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base