def handle_sigint_silent(signal, frame): with l: for c in get_stack_dump(): log.devinfo(c) logging.shutdown() # Since we want to terminate worker threads with prejudice, # we use os._exit, which directly terminates the process. # otherwise the worker try/catch will also catch the SystemExit os.exit_(-1)
print "URL Error - " + str(url) return if page.status_code == 200: continue_ = process_page(url, page, last_dt, pg_num, conn, cur, sql_table) print "{0} - Page {1}".format(url, pg_num) if continue_: scrape_biz(url, pg_num=pg_num+1) else: print url, "- Done!" elif page.status_code == 503: print "Blocked. Terminating..." os.exit_(1) return def process_page(url, page, last_dt, pg_num, conn, cur, sql_table): """ Process page, insert reviews into DB, and return flag to continue.\ """ soup = BeautifulSoup(page.text) try: pages = int(soup.find('div', {'class': "page-of-pages arrange_unit arrange_unit--fill"}) .text.split()[-1]) except: print "No reviews - ", url return 0
import os from socket import * host = "127.0.0.1" # set to IP address of target computer port 13000 addr = (host, port) UDPSock = socket(AF_INET, SOCK_DGRAM) while True: data = raw_input("Enter message to send or type 'exit':") UDPSock.sendto(data, addr) if data == "exit": break UDPSock.close() os.exit_(0)