Hello. There is such a code:
def actions(host,i): while True: time.sleep(1) def main(): hosts = [] with open('host.txt') as hosts_file: for line in hosts_file: hosts.append(line.strip()) for (i, host) in enumerate(hosts): thread = Process(target=actions, args=(host,i)) thread.start() if __name__ == '__main__': try: main() except KeyboardInterrupt: pass The code takes a list of hosts from the hosts.txt file and sends each host from the file to its process (ala multithreading), in which with each host some time-out actions are performed endlessly. The problem is that even if the actions function without the main code (as in the example above), after some time from the start, the program freezes like the whole OS (Ubuntu 16.04), it seems like all the RAM is being devoured, and its 32GB. Please tell me how to optimize this code.