Created
March 26, 2015 06:06
-
-
Save anonymous/5d7d198cd3c22b31fa2a to your computer and use it in GitHub Desktop.
Python 2.7 file sync bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
int main(int argc, char**argv) | |
{ | |
HANDLE handle = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, | |
OPEN_EXISTING, 0, NULL); | |
int size = GetFileSize(handle, NULL); | |
CloseHandle(handle); | |
return size; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import os | |
import subprocess | |
import tempfile | |
import threading | |
import time | |
def do_work(): | |
indata = b"[numthreads(32,32,1)] void main() {}" | |
infd, infilename = tempfile.mkstemp() | |
os.close(infd) | |
try: | |
with open(infilename, 'wb') as infile: | |
infile.write(indata) | |
infile.flush() | |
os.fsync(infile.fileno()) | |
cmdline = ["child", infilename] | |
retcode = subprocess.call(cmdline) | |
if retcode != len(indata): | |
print("Failure, got {} but expected {}".format(retcode, len(indata))) | |
finally: | |
time.sleep(0.5) | |
os.remove(infilename) | |
def start_thread(): | |
thread = threading.Thread(target=do_work) | |
thread.start() | |
return thread | |
def main(): | |
num_threads = 10 | |
print("Spawning {} threads".format(num_threads)) | |
threads = [ start_thread() for x in range(num_threads) ] | |
results = [ thread.join() for thread in threads ] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment