You can use something such as Queue.Queue (the module is here: Queue) and threading.Thread (or threading.start_new_thread if you just want a function), the module is here: threading - As a file write is not CPU intensive and use more IO. (and the GIL doesn't affect it).