@@ -364,13 +364,6 @@ impl RMain {
364
364
365
365
let main = RMain :: get_mut ( ) ;
366
366
367
- // Initialize the GD context on this thread
368
- graphics_device:: init_graphics_device (
369
- main. get_comm_manager_tx ( ) . clone ( ) ,
370
- main. get_iopub_tx ( ) . clone ( ) ,
371
- graphics_device_rx,
372
- ) ;
373
-
374
367
let mut r_args = r_args. clone ( ) ;
375
368
376
369
// Record if the user has requested that we don't load the site/user level R profiles
@@ -488,6 +481,18 @@ impl RMain {
488
481
) ;
489
482
Self :: complete_initialization ( main. banner . take ( ) , kernel_init_tx) ;
490
483
484
+ // Initialize the GD context on this thread.
485
+ // Note that we do it after init is complete to avoid deadlocking
486
+ // integration tests by spawning an async task. The deadlock is caused
487
+ // by https://github.com/posit-dev/ark/blob/bd827e735970ca17102aeddfbe2c3ccf26950a36/crates/ark/src/r_task.rs#L261.
488
+ // We should be able to remove this escape hatch in `r_task()` by
489
+ // instantiating an `RMain` in unit tests as well.
490
+ graphics_device:: init_graphics_device (
491
+ main. get_comm_manager_tx ( ) . clone ( ) ,
492
+ main. get_iopub_tx ( ) . clone ( ) ,
493
+ graphics_device_rx,
494
+ ) ;
495
+
491
496
// Now that R has started and libr and ark have fully initialized, run site and user
492
497
// level R profiles, in that order
493
498
if !ignore_site_r_profile {
0 commit comments