Skip to content

Commit 0595dd9

Browse files
committed
Delay initialisation of graphics device
1 parent 6486bf3 commit 0595dd9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crates/ark/src/interface.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,6 @@ impl RMain {
364364

365365
let main = RMain::get_mut();
366366

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-
374367
let mut r_args = r_args.clone();
375368

376369
// Record if the user has requested that we don't load the site/user level R profiles
@@ -488,6 +481,18 @@ impl RMain {
488481
);
489482
Self::complete_initialization(main.banner.take(), kernel_init_tx);
490483

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+
491496
// Now that R has started and libr and ark have fully initialized, run site and user
492497
// level R profiles, in that order
493498
if !ignore_site_r_profile {

0 commit comments

Comments
 (0)