Q:

Closing Selenium webdriver after X seconds

I am using selenium webdriver (firefox) on Ubuntu + Python, and run into an issue where sometimes the page doesn't load, and the whole script simply hangs. 
Is there a way to force-exit the webdriver window after X seconds ? 
Looking for code like the one below, that actually works though.   It looks like if the webdriver is waiting on the response, it will wait (almost) indefinitely). 
driver.get(record)
sleep(5)
my_html = driver.page_source #get whatever we have after 5 sec
driver.close() #close driver

NOTE!:  The accepted answer is correct.   The issue was caused by my geckodriver being out of date (v 0.11 vs v.019). 
To check your version on ubuntu:
geckodriver --version   #command in terminal

to update the driver (if needed), use these steps.   Note - Sandeep's answer worked best for me. 

A:

from selenium import webdriver
from time import sleep

record = "https://www.google.com"
driver = webdriver. Firefox()
driver.set_page_load_timeout(30)
try:
    driver.get(record)
    my_html = driver.page_source #get whatever we have after 5 sec
finally:
    driver.close()

Setting page load timeout, as described here, will achieve what you're after.   It will raise a TimeoutException if the page doesn't load within the time given, closing the program.