I am using multiprocessing in python, try to kill the running after a timeout. But it doesn't work, and I don't know the reason.
I followed an example, it seems easy. Just need to start the process, after 2 seconds, terminate the running. But it doesnt work for me.
Could you please help me figure it out? Thanks for your help!
from amazonproduct import API import multiprocessing import time AWS_KEY = '...' SECRET_KEY = '...' ASSOC_TAG = '...' def crawl(): api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG) for root in api.item_search('Beauty', Keywords='maybelline', ResponseGroup='Large'): # extract paging information nspace = root.nsmap.get(None, '') products = root.xpath('//aws:Item', namespaces={'aws' : nspace}) for product in products: print product.ASIN, if __name__ == '__main__': p = multiprocessing.Process(target = crawl()) p.start() if time.sleep(2.0): p.terminate()