Skip to content

Commit

Permalink
Fix early quit exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Jan 26, 2017
1 parent 2eeef92 commit f467f68
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/collective/behavior/featuredimage/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from PIL import Image
from plone.namedfile.file import NamedBlobImage
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

import signal
import transaction
Expand All @@ -16,13 +19,14 @@ def _get_screenshot(page):
browser.get(page)
data = browser.get_screenshot_as_png()
# crop image
el = browser.find_element_by_id('featuredimage')
# XXX: quit() does not terminate PhantomJS process
# https://github.com/SeleniumHQ/selenium/issues/767
browser.service.process.send_signal(signal.SIGTERM)
browser.quit()
el = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, 'featuredimage'))
)
# Put these lines after browser.quit will raise URLError exception
location = el.location
size = el.size
browser.service.process.send_signal(signal.SIGTERM)
browser.quit()
im = Image.open(StringIO(data))
im = im.crop((
location['x'], location['y'],
Expand Down

0 comments on commit f467f68

Please sign in to comment.