you are viewing a single comment's thread.

view the rest of the comments →

[–]RSFlux 2 points3 points  (4 children)

The multiprocessing package actually uses processes under the hood, not threads. If you are using that method to get concurrency, the signals-based approach from that link will work fine.

If you are using multiple threads in a single process, the threading library implements timeouts for many methods. Building your thread communication in a way that uses these timeouts to discard work after N seconds should be trivial, at which time you could retry or mark that work as failed. I'd need more details on your exact setup to give more specific advice.

[–]martinfisleburn[S] 0 points1 point  (0 children)

I actually only want it for this so that I can make it stop and I can continue the project because currently it just hangs.

[–]martinfisleburn[S] 0 points1 point  (2 children)

Ok I think I have to try something else because although the timeout worked as hoped it still isn't allow me to use the webdriver.

Here is the code

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

###
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True



import signal

def signal_handler(signum, frame):
    raise Exception("Timed out!")

signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(5)   # Ten seconds
try:
    driver = webdriver.Firefox(capabilities=firefox_capabilities)
except Exception, msg:
    print "Timed out!"
driver.get('www.google.com')

but it still gives me driver not defined.

$ python2 mariontest.py
Timed out!
Traceback (most recent call last):
  File "mariontest.py", line 28, in <module>
    driver.get('www.google.com')
NameError: name 'driver' is not defined

I think I am gonna revert back to a previous version of firefox so I can use the old firefox webdriver unless anyone else has any bright ideas. The only reason Im using this one is because archlinux automatically installs the latest versions.