I have two incoming streaming, both of them are big. can I flush the first data, let say from the file's position 1 to 512 and the other from 513 to 1023? Note that that both streams are coming parallelly.
thanks!
I have two incoming streaming, both of them are big. can I flush the first data, let say from the file's position 1 to 512 and the other from 513 to 1023? Note that that both streams are coming parallelly.
thanks!
Not sure exactly what you mean by parallel, but you can write to two different file objects that have the same file open. I assume it doesn't matter if you are using threads or an event loop.
>>> f1 = open("/tmp/foo", "a")
>>> f2 = open("/tmp/foo", "a")
>>> f1.write("a\n")
>>> f2.write("b\n")
>>> f1.close()
>>> f2.close()
>>> print open("/tmp/foo").read()
a
b
Sure, you can do it. Are you guaranteed correct results? No. Use locks or mmap as suggested by Ignacio.
Here's a good discussion too: Python multiple threads accessing same file