This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients andrewnester, christian.heimes, jwilk, rhettinger, richardxia
Date 2017-03-27.20:27:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1490646457.25.0.814103945064.issue29573@psf.upfronthosting.co.za>
In-reply-to
Content
Raymond, I think Richard's approach is problematic at best. 

Richard, you cannot use a NamedTempFile with an external process like that. At least you have to flush the file to disk. Even flushing is not safely portable. The safest and most portable approach is to close the file, call the other process and then unlink the file manually:

with tempfile.NamedTemporaryFile(delete=False) as f:
    try:    
        f.write(b'data')
        f.close()
        subprocess.Popen(['binutil', f.name, ...])
    finally:
        os.unlink(f.name)


It's too bad that close() on a NamedTemporaryFile(delete=True) deletes the files. For your problem it would be beneficial to have __exit__() perform the unlink operation.
History
Date User Action Args
2017-03-27 20:27:37christian.heimessetrecipients: + christian.heimes, rhettinger, jwilk, andrewnester, richardxia
2017-03-27 20:27:37christian.heimessetmessageid: <1490646457.25.0.814103945064.issue29573@psf.upfronthosting.co.za>
2017-03-27 20:27:37christian.heimeslinkissue29573 messages
2017-03-27 20:27:37christian.heimescreate