user2966332
user2966332

Reputation: 1

Python multiple instances of program writing and then reading the same file

I wrote a piece of python code that calls a external program to write an intermediate file and thereafter my code reads from it. I want to run multiple instances of my code simultaneously. Will there be any conflict if I code list this?

args=['/usr/bin/program','-o','intermediate_file']
process = subprocess.Popen(args,shell=False)
process.wait()
if process.returncode ==0:
    fh = open('intermediate_file', 'r')
    process(fh)
        ...

Upvotes: 0

Views: 1313

Answers (2)

WeaselFox
WeaselFox

Reputation: 7380

Take a look here: tempfile

You can make use of this lib to avoid conflicts - temp files have random names.

Upvotes: 0

Thomas Junk
Thomas Junk

Reputation: 5676

Concurrent file access is handled by the operating system. There are several scenarios, depending on the OS and or filesystem you use. Take a look at the Wikipedia-article.

Upvotes: 3

Related Questions