0
我已經構建了一個無限循環運行的刮板。它還在10臺以上的AWS機器上使用代理池。我想讓它看起來像是一次IP碰到X次,那麼它不應該再次被擊中,到目前爲止,我用MySQL來達到目的。問題是,如果所有代理完成配額,如何讓它睡眠或延遲,並在新的一天獲得新的生命。現在我沒下,但最終它會終止整個程序:Python:如果某個條件滿足,如何殺死或睡眠一個進程?
def parse():
if random_proxy == '': # ALL Proxies finished quota for the day
raise Exception('Proxy Not Found')
r = session.get(u, headers=headers, proxies={'https': proxy_url})
if __name__ == '__main__':
idx = 0
exception_string = ''
POOL_COUNT = 50
try:
if conn is not None:
links = get_links(conn, POOL_COUNT)
if conn.open:
conn.close()
with Pool(POOL_COUNT) as p:
result = p.map(parse, links)
except Exception as ex:
print('Main program exception')
閱讀[同步原語](https://docs.python.org/3.6/library/multiprocessing.html#synchronization-primitives) – stovfl