cgoldberg / xvfbwrapper

Manage headless displays with Xvfb (X virtual framebuffer)
Other
295 stars 52 forks source link

Support gracefully shutdown when SIGINT/Ctrl+C #31

Closed pjw91 closed 6 years ago

pjw91 commented 6 years ago

Detach subprocess from interpreter's process group, avoids receiving SIGINT from it.

When hitting Ctrl+C, the subprocess Xvfb (and webdriver/selenium), receives SIGINT and shutdown, probably before the custom clean-up code. (race condition)

If I use a class Page to wrap around selenium, and have a clean-up code in exit to close the opened window:

class Page:
  def __init__(self, wd):
    self.wd=wd
  def __enter__(self):
    // open window by js, and calculate the opened window handle
    self.window = // set(new_window_handles) - set(new_window_handles)
  def __exit__(self, *a):
    //xvfb and webdriver stop here, and...
    self.switch_to(self.window)  // cause this line fails
    self.close()
cgoldberg commented 6 years ago

thanks!

pjw91 commented 6 years ago

Actually, this patch forces the user to properly shutdown the Xfvb; otherwise, it would be an orphan process.

Shall this become an optional feature?

cgoldberg commented 6 years ago

I just reverted this in master for now. Will investigate when I have time.