randy3k / radian

A 21 century R console
MIT License
2.03k stars 76 forks source link

signal only works in main thread of the main interpreter #294

Open renkun-ken opened 3 years ago

renkun-ken commented 3 years ago

Running the following torch example in latest radian will crash:

# install.packages("torch")
# install.packages("torchvision")
# remotes::install_github("mlverse/torchdatasets")

library(torch)
library(torchvision)
library(torchdatasets)

torch_tensor(1)

train_indices <- 1:10000
val_indices <- 10001:15000
test_indices <- 15001:20000

add_channel_dim <- function(img) img$unsqueeze(1)
crop_axes <- function(img) transform_crop(img, top = 0, left = 21, height = 131, width = 130)

root <- file.path(tempdir(), "correlation")

train_ds <- guess_the_correlation_dataset(
  # where to unpack
  root = root,
  # additional preprocessing
  transform = function(img) crop_axes(img) %>% add_channel_dim(),
  # don't take all data, but just the indices we pass in
  indexes = train_indices,
  download = TRUE
)

valid_ds <- guess_the_correlation_dataset(
  root = root,
  transform = function(img) crop_axes(img) %>% add_channel_dim(),
  indexes = val_indices,
  download = FALSE
)

test_ds <- guess_the_correlation_dataset(
  root = root,
  transform = function(img) crop_axes(img) %>% add_channel_dim(),
  indexes = test_indices,
  download = FALSE
)

length(train_ds)
length(valid_ds)
length(test_ds)

train_ds[1]

train_dl <- dataloader(train_ds, batch_size = 64, shuffle = TRUE)
length(train_dl)

batch <- dataloader_make_iter(train_dl) %>% dataloader_next()

dim(batch$x)
dim(batch$y)

par(mfrow = c(8, 8), mar = rep(0, 4))

An infinite loop of printing <class 'ValueError'> signal only works in main thread of the main interpreter in the prompt will appear and enter any command will end up in the following error:

> <class 'ValueError'> signal only works in main thread of the main interpreter                                                                                                            
> <class 'ValueError'> signal only works in main thread of the main interpreter                                                                                                            
> <class 'ValueError'> signal only works in main thread of the main interpreter                                                                                                            
> <class 'ValueError'> signal only works in main thread of the main interpreter                                                                                                            
<class 'ValueError'> signal only works in main thread of the main interpreter
unexpected error was caught.
please report to https://github.com/randy3k/radian for such error.
Event loop is already running
unexpected error was caught.
please report to https://github.com/randy3k/radian for such error.
list.remove(x): x not in list
Traceback (most recent call last):
  File "/home/renkun/.local/lib/python3.9/site-packages/radian/console.py", line 96, in read_console
    text = session.prompt(add_history=add_history)
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/prompt.py", line 231, in prompt
    result = super(ModalPromptSession, self).prompt(**kwargs)
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/shortcuts/prompt.py", line 797, in prompt
    return run_sync()
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/shortcuts/prompt.py", line 786, in run_sync
    return self.app.run(inputhook=self.inputhook, pre_run=pre_run2)
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/application/application.py", line 736, in run
    return run()
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/application/application.py", line 709, in run
    run_until_complete(f, inputhook=inputhook)
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/eventloop/defaults.py", line 126, in run_until_complete
    return get_event_loop().run_until_complete(future, inputhook=inputhook)
  File "/home/renkun/.local/lib/python3.9/site-packages/lineedit/deps/prompt_toolkit/eventloop/posix.py", line 58, in run_until_complete
    raise Exception('Event loop is already running')
Exception: Event loop is already running

My session info:

> sessioninfo::session_info()                                                                                                                                                              
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.0 (2021-05-18)
 os       Ubuntu 21.04                
 system   x86_64, linux-gnu           
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Asia/Shanghai               
 date     2021-07-07                  

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package       * version    date       lib source                                
 bit             4.0.4      2020-08-04 [1] CRAN (R 4.1.0)                        
 bit64           4.0.5      2020-08-30 [1] CRAN (R 4.1.0)                        
 callr           3.7.0      2021-04-20 [1] CRAN (R 4.1.0)                        
 cli             3.0.0      2021-06-30 [1] CRAN (R 4.1.0)                        
 coro            1.0.1      2020-12-17 [1] CRAN (R 4.1.0)                        
 jsonlite        1.7.2      2020-12-09 [1] CRAN (R 4.1.0)                        
 magrittr        2.0.1      2020-11-17 [1] CRAN (R 4.1.0)                        
 processx        3.5.2      2021-04-30 [1] CRAN (R 4.1.0)                        
 ps              1.6.0      2021-02-28 [1] CRAN (R 4.1.0)                        
 Rcpp            1.0.6      2021-01-15 [1] CRAN (R 4.1.0)                        
 rlang           0.4.11     2021-04-30 [1] CRAN (R 4.1.0)                        
 sessioninfo     1.1.1      2018-11-05 [1] CRAN (R 4.1.0)                        
 torch         * 0.4.0      2021-06-10 [1] CRAN (R 4.1.0)                        
 torchdatasets * 0.0.1.9000 2021-07-07 [1] Github (mlverse/torchdatasets@e98a8e3)
 torchvision   * 0.3.0      2021-05-04 [1] CRAN (R 4.1.0)                        
 withr           2.4.2      2021-04-18 [1] CRAN (R 4.1.0)                        

[1] /home/renkun/R/x86_64-pc-linux-gnu-library/4.1
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
randy3k commented 3 years ago

It runs fine on my computer. Were you trying to send a signal to the process?

randy3k commented 3 years ago

Prehapa Linux issue, let me try it on a linux.