代码如下: 代码示例:
# -*- coding: utf-8 -*-
#多进程分块读取文件
import urlparse
import datetime
import os
from multiprocessing import Process,Queue,Array,RLock
WORKERS = 6
BLOCK_SIZE = 0
FILE_SIZE = 0
FILE_NAME = 'try.log'
def getFilesize(file):
global FILE_SIZE
fs = open(file,'r')
fs.seek(0,os.SEEK_END)
FILE_SIZE = fs.tell()
fs.close()
def process_found(pid,array,rlock):
global FILE_SIZE,BLOCK_SIZE
fs = open(FILE_NAME,'rb')
try:
rlock.acquire()
begin = array[0]
end = (begin + BLOCK_SIZE)
print begin,end
if begin >= FILE_SIZE:
print 'begin',begin
array[0] = begin
raise Exception('end of file')
if end < FILE_SIZE: