import os import tempfile import threading import subprocess import win32file import win32con import win32api def touch(filename): process = subprocess.Popen("touch " + filename , stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) process.wait() def remove(filename): os.remove(filename) class this(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.start() def run(self): for i in range(0, 100): #filename = tempfile.mktemp() (temp_file_handler, filename) = tempfile.mkstemp() os.close(temp_file_handler) del temp_file_handler handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.OPEN_EXISTING, 0, None) win32file.WriteFile(handle, b'test') handle.Close() touch(filename) remove(filename) getters = [] for i in range(0, 10): getter = this() getters.append(getter) for getter in getters: getter.join()