我正在写网络共享,这是写一段代码
while not created:
fileName = ''.join(random.choice(CANDIDATE_CHARS) for x in range(len))
fullPath = os.path.join(base, fileName)
if not os.path.exists(fullPath):
filesize = random.randint(fileSizeLowerLim, fileSizeUpperLim)
logger.info("Creating file %s, with size %d" %(fullPath, filesize))
with open(fullPath, 'wb') as fout:
if filesize > 0:
fout.write(os.urandom(filesize * 1048576))
sizeLimit -= filesize
allFiles.append(fullPath)
created = True
logger.info("Created file %s, now limit is %d" %(fullPath, sizeLimit))
我收到了这个错误:
fout.write(os.urandom(filesize * 1048576))
IOError: [Errno 22] Invalid argument
job remoteMachine finished ended with rc = 1
remoteMachine finished and it failed
当我查看文件时,它已生成但没有数据。我在python中错过了什么?
我使用32位python在Windows 7上运行脚本。
答案 0 :(得分:2)
我怀疑你的“urandom”缓冲区超过64MB因此点击了一个Windows operating system limit,在writing to a network share时同样会影响其他人。