def retry_mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>', directory=None, max_retries=<NUM_LIT:3>):
if directory is None:<EOL><INDENT>directory = current_app.config['<STR_LIT>']<EOL><DEDENT>for retry_count in range(<NUM_LIT:1>, max_retries + <NUM_LIT:1>):<EOL><INDENT>try:<EOL><INDENT>tmp_file_fd, tmp_file_name = tempfile.mkstemp(suffix=suffix,<EOL>prefix=prefix,<EOL>dir=directory)<EOL><DEDENT>except OSError as e:<EOL><INDENT>if e.errno == <NUM_LIT> and retry_count <= max_retries:<EOL><INDENT>time.sleep(<NUM_LIT:10>)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return tmp_file_fd, tmp_file_name<EOL>
Make mkstemp more robust against AFS glitches.