Python Multiprocess multipart access to ultra-large files

Source: Internet
Author: User
This article describes how to read large files by multiple processes in multiple parts in Python, and related skills related to Python multi-process operations and file multipart reading, for more information about how to read ultra-large files in multiple Python processes, see the example in this article. We will share this with you for your reference. The details are as follows:

Read ultra-large text files and use multi-process multipart reading to output each file separately

#-*-Coding: GBK-*-import urlparseimport datetimeimport osfrom multiprocessing import Process, Queue, Array, RLock "multi-process multipart file Reading" WORKERS = 4 BLOCKSIZE = too many file_size = 0def getFilesize (file ): "Get the size of the file to be read" global FILE_SIZE fstream = open (file, 'R') fstream. seek (0, OS. SEEK_END) FILE_SIZE = fstream. tell () fstream. close () def process_found (pid, array, file, rlock): global FILE_SIZE global JOB global PREFIX "process processing Args: pid: Process number array: inter-process shared queue, used to mark the end position of the file block read by each process. file: name of the read file. Each process first obtains the endpossition (startpossition + BLOCKSIZE) position where the current maximum value is startpossition from the array) if (startpossition + BLOCKSIZE)
 
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.