webmail.gandi.net
2024-Feb-20 11:27 UTC
[Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2
Dear list,
It seems that something changed between R 4.2.3 and R 4.3 (tested with 4.3.2)
that broke the Tcl socket server. Here is a reproducible example:
- R process #1 (Tcl socket server):
library(tcltk)
cmd <- r"(
proc accept {chan addr port} { ;# Make a proc to accept connections
puts "$addr:$port says [gets $chan]" ;# Receive a string
puts $chan goodbye ;# Send a string
close $chan ;# Close the socket (automatically
flushes)
} ;#
socket -server accept 12345 ;# Create a server socket)"
.Tcl(cmd)
- R process #2 (socket client):
con <- socketConnection(host = "localhost", port = 12345, blocking
= FALSE)
writeLines("Hello, world!", con) # Should print something in R #1
stdout
readLines(con) # Should receive "goodbye"
close(con)
When R process #1 is R 4.2.3, it works as expected (whatever version of R #2).
When R process #1 is R 4.3.2, nothing is sent or received through the socket
apparently, but no error is issued and process #2 seems to be able to connect to
the socket.
I am stuck with this. Thanks in advance for help.
Regards,
Philippe
> .Tcl("puts [info patchlevel]")
8.6.13
<Tcl>
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1
Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;
LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/Brussels
tzcode source: internal
attached base packages:
[1] tcltk stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2 glue_1.7.0
Dirk Eddelbuettel
2024-Feb-20 12:15 UTC
[Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2
On 20 February 2024 at 12:27, webmail.gandi.net wrote:
| Dear list,
|
| It seems that something changed between R 4.2.3 and R 4.3 (tested with 4.3.2)
that broke the Tcl socket server. Here is a reproducible example:
|
| - R process #1 (Tcl socket server):
|
| library(tcltk)
| cmd <- r"(
| proc accept {chan addr port} { ;# Make a proc to accept connections
| puts "$addr:$port says [gets $chan]" ;# Receive a string
| puts $chan goodbye ;# Send a string
| close $chan ;# Close the socket (automatically
flushes)
| } ;#
| socket -server accept 12345 ;# Create a server socket)"
| .Tcl(cmd)
|
| - R process #2 (socket client):
|
| con <- socketConnection(host = "localhost", port = 12345,
blocking = FALSE)
| writeLines("Hello, world!", con) # Should print something in R #1
stdout
| readLines(con) # Should receive "goodbye"
| close(con)
|
| When R process #1 is R 4.2.3, it works as expected (whatever version of R #2).
When R process #1 is R 4.3.2, nothing is sent or received through the socket
apparently, but no error is issued and process #2 seems to be able to connect to
the socket.
|
| I am stuck with this. Thanks in advance for help.
>From a quick check this issue seems to persist in the (current) R-devel
2024-02-20 r85951 too.
Dirk
| Regards,
|
| Philippe
|
| > .Tcl("puts [info patchlevel]")
| 8.6.13
| <Tcl>
|
| > sessionInfo()
| R version 4.3.2 (2023-10-31)
| Platform: aarch64-apple-darwin20 (64-bit)
| Running under: macOS Sonoma 14.2.1
|
| Matrix products: default
| BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
| LAPACK:
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;
LAPACK version 3.11.0
|
| locale:
| [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
|
| time zone: Europe/Brussels
| tzcode source: internal
|
| attached base packages:
| [1] tcltk stats graphics grDevices utils datasets methods base
|
| loaded via a namespace (and not attached):
| [1] compiler_4.3.2 tools_4.3.2 glue_1.7.0
| ______________________________________________
| R-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel
--
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Ivan Krylov
2024-Feb-20 16:13 UTC
[Rd] Tcl socket server (tcltk) does not work any more on R 4.3.2
? Tue, 20 Feb 2024 12:27:35 +0100 "webmail.gandi.net" <phgrosjean at sciviews.org> ?????:> When R process #1 is R 4.2.3, it works as expected (whatever version > of R #2). When R process #1 is R 4.3.2, nothing is sent or received > through the socket apparently, but no error is issued and process #2 > seems to be able to connect to the socket.The difference is related to the change in src/library/tcltk/src/tcltk_unix.c. In R-4.2.1, the function static void TclSpinLoop(void *data) says: int max_ev = 100; /* Tcl_ServiceAll is not enough here, for reasons that escape me */ while (Tcl_DoOneEvent(TCL_DONT_WAIT) && max_ev) max_ev--; In R-devel, the function instead says: int i = R_TCL_SPIN_MAX; while (i-- && Tcl_ServiceAll()) ; Manually calling Tcl_DoOneEvent(0) from the debugger at this point makes the Tcl code respond to the connection. Tcl_ServiceAll() seems to be still not enough. I'll try reading Tcl documentation to investigate this further. -- Best regards, Ivan