Search code examples
rubyimagemagickrmagick

RMagicK image.display does not return immediately


I am using RMagicK for Ruby to draw and display images. The problem is that after:

img = rvg.draw()
img.diaplay

control is not returned to the caller immediately. The user has to manually close the window for the program to continue. How can I bypass this behavior?


Solution

  • You could create a sub-process that takes care of displaying the image for you, while you do some processing in the main process.

    img = rvg.draw()
    pid = fork { img.diaplay }
    
    Process.detach(pid) # wait for the child in another thread.
    
    # more code
    

    Note that, fork is not available in some platforms, like Windows. You might have to use spawn if that's a problem for you.