parameters: (fathom_fox, show_browser, geckodriver_path)
docstring: Configure and return a running Firefox to run the vectorizer with.
  
      Sets headless mode, sets the download directory to a temp directory, turns
      off page caching, and installs FathomFox. Tries its best to quit Firefox
      afterward.
docstring_summary: Configure and return a running Firefox to run the vectorizer with.
docstring_tokens: Configure and return a running Firefox to run the vectorizer with .
function: def running_firefox(fathom_fox, show_browser, geckodriver_path):
      """Configure and return a running Firefox to run the vectorizer with.
  
      Sets headless mode, sets the download directory to a temp directory, turns
      off page caching, and installs FathomFox. Tries its best to quit Firefox
      afterward.
  
      """
      print('Running Firefox...', end='', flush=True)
      options = webdriver.FirefoxOptions()
      options.headless = not show_browser
  
      with TemporaryDirectory() as download_dir:
          profile = webdriver.FirefoxProfile()
          profile.set_preference('browser.download.folderList', 2)
          profile.set_preference('browser.download.dir', download_dir)
          profile.set_preference('browser.cache.disk.enable', False)
          profile.set_preference('browser.cache.memory.enable', False)
          profile.set_preference('browser.cache.offline.enable', False)
          profile.set_preference('devtools.chrome.enabled', True)
  
          firefox = webdriver.Firefox(
              executable_path=str(geckodriver_path.resolve()),
              options=options,
              firefox_profile=profile,
              service_log_path=devnull,
          )
  
          firefox.install_addon(str(fathom_fox), temporary=True)
          firefox_pid = firefox.capabilities['moz:processID']
          geckodriver_pid = firefox.service.process.pid
          print('done.')
  
          # There is a graceful shutdown path and an ungraceful shutdown path. If
          # the vectorizer has started running, we use the ungraceful shutdown
          # path. This is because Firefox becomes unresponsive to the call to
          # `quit()`.
          graceful_shutdown = False
          try:
              yield firefox
              graceful_shutdown = True
          except GracefulError:
              graceful_shutdown = True
              raise  # happens AFTER the finally
          finally:
              if graceful_shutdown:
                  firefox.quit()
              else:
                  # This is the only way I could get killing the program with
                  # ctrl+c to work properly.
                  signal_for_killing = (signal.CTRL_C_EVENT if os.name == 'nt'
                                        else signal.SIGTERM)
                  try:
                      # https://bugzilla.mozilla.org/show_bug.cgi?id=1430064
                      kill(firefox_pid, signal_for_killing)
                  except (SystemError, ProcessLookupError):
                      pass
                  kill(geckodriver_pid, signal_for_killing)
function_tokens: def running_firefox ( fathom_fox , show_browser , geckodriver_path ) : print ( 'Running Firefox...' , end = '' , flush = True ) options = webdriver . FirefoxOptions ( ) options . headless = not show_browser with TemporaryDirectory ( ) as download_dir : profile = webdriver . FirefoxProfile ( ) profile . set_preference ( 'browser.download.folderList' , 2 ) profile . set_preference ( 'browser.download.dir' , download_dir ) profile . set_preference ( 'browser.cache.disk.enable' , False ) profile . set_preference ( 'browser.cache.memory.enable' , False ) profile . set_preference ( 'browser.cache.offline.enable' , False ) profile . set_preference ( 'devtools.chrome.enabled' , True ) firefox = webdriver . Firefox ( executable_path = str ( geckodriver_path . resolve ( ) ) , options = options , firefox_profile = profile , service_log_path = devnull , ) firefox . install_addon ( str ( fathom_fox ) , temporary = True ) firefox_pid = firefox . capabilities [ 'moz:processID' ] geckodriver_pid = firefox . service . process . pid print ( 'done.' ) # There is a graceful shutdown path and an ungraceful shutdown path. If # the vectorizer has started running, we use the ungraceful shutdown # path. This is because Firefox becomes unresponsive to the call to # `quit()`. graceful_shutdown = False try : yield firefox graceful_shutdown = True except GracefulError : graceful_shutdown = True raise # happens AFTER the finally finally : if graceful_shutdown : firefox . quit ( ) else : # This is the only way I could get killing the program with # ctrl+c to work properly. signal_for_killing = ( signal . CTRL_C_EVENT if os . name == 'nt' else signal . SIGTERM ) try : # https://bugzilla.mozilla.org/show_bug.cgi?id=1430064 kill ( firefox_pid , signal_for_killing ) except ( SystemError , ProcessLookupError ) : pass kill ( geckodriver_pid , signal_for_killing )