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 2371356
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 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,20 @@ 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()
location = el.location
size = el.size
location = None
size = None
try:
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
finally:
browser.service.process.send_signal(signal.SIGTERM)
browser.quit()
if location is None or size is None:
return
im = Image.open(StringIO(data))
im = im.crop((
location['x'], location['y'],
Expand Down

0 comments on commit 2371356

Please sign in to comment.