Multithreading Batch Processing Framework

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # Author: f0rsaken
 4
 5 import argparse
 6 import importlib
 7 import sys
 8 import threadpool
 9 import time
10
11 def main():
12     parser = argparse.ArgumentParser(description="Multithreading Batch Processing Framework")
13     parser.add_argument("-p", "--plugin", type=open, required=True, help="plugin file")
14     parser.add_argument("-i", "--input", type=open, required=True, help="input file")
15     parser.add_argument("-t", "--thread", default=1, type=int, help="number of threads")
16
17     try:
18         args = parser.parse_args()
19     except FileNotFoundError as e:
20         print(e)
21         sys.exit(1)
22
23     poolsize = args.thread
24     some_callable = get_some_callable(args.plugin)
25     list_of_args = get_list_of_args(args.input)
26
27     global log
28     log = str(int(time.time())) + ".txt"
29
30     pool = threadpool.ThreadPool(poolsize)
31     reqs = threadpool.makeRequests(some_callable, list_of_args, callback)
32     [pool.putRequest(req) for req in reqs]
33     pool.wait()
34     pool.dismissWorkers(poolsize)
35     pool.joinAllDismissedWorkers()
36
37 def get_some_callable(plugin):
38     try:
39         plugin = importlib.import_module(plugin.name.split(".")[0])
40         some_callable = plugin.exploit
41     except (AttributeError, ImportError) as e:
42         print(e)
43         sys.exit(1)
44     else:
45         return some_callable
46
47 def get_list_of_args(input):
48     list_of_args = list()
49     list_of_temp = input.readlines()
50     for i in list_of_temp:
51         list_of_args.append(i.strip())
52     return list_of_args
53
54 def callback(request, result):
55     if result:
56         with open(log, "a") as f:
57             f.write(result + "\n")
58         print(result)
59
60 if __name__ == "__main__":
61     main()
时间: 2024-10-17 19:37:23

Multithreading Batch Processing Framework的相关文章

Apache Hadoop YARN: Moving beyond MapReduce and Batch Processing with Apache Hadoop 2

Apache Hadoop YARN: Moving beyond MapReduce and Batch Processing with Apache Hadoop 2 .mobi: http://www.t00y.com/file/79497801 Apache Hadoop YARN: Moving beyond MapReduce and Batch Processing with Apache Hadoop 2.pdf: http://www.t00y.com/file/8034244

Batch Processing

下面例子展示批量插入一个反模式(不成熟使用Hibernate插入100000行记录) Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for ( int i=0; i<100000; i++ ) {  Customer customer = new Customer(.....);  session.save(customer); } tx.commit();

SAP中的BOPF(Business Object Processing Framework)

https://www.cnblogs.com/hhelibeb/p/8227382.html 目录 BOPF代表什么? 谁在使用BOPF? 怎样才能使用BOPF? 应用基础设施的主要组件有哪些? UI和消费 处理集成 基础设施组件 编程模型包含哪些元素? 在哪些开发环境中BOPF可用? 注意 教程 正文 希望简化你的业务应用开发过程?业务对象处理框架(Business Object Processing Framework,以下简称BOPF)也许可以帮到你. BOPF是SAP Business

NHibernate大批量插入数据库的处理方法 NHibernate Batch processing

使用NHibernate插入接近100000条记录到数据库,像下面一个例子: ISession session = sessionFactory.OpenSession(); ITransaction tx = session.BeginTransaction(); for ( int i=0; i<100000; i++ ) { Customer customer = new Customer(.....); session.Save(customer); } tx.Commit(); ses

Drill中实现HTTP storage plugin

Apache Drill可用于大数据的实时分析,引用一段介绍: 受到Google Dremel启发,Apache的Drill项目是对大数据集进行交互式分析的分布式系统.Drill并不会试图取代已有的大数据批处理框架(Big Data batch processing framework),如Hadoop MapReduce或流处理框架(stream processing framework),如S4和Storm.相反,它是要填充现有空白的--对大数据集的实时交互式处理 简单来说,Drill可接收

Java软件工程师技能图谱

原文链接:Java软件工程师技能图谱 最近在考虑"拥有怎样的技能才能算一名合格的java软件工程师呢?"这个问题.碰巧在github发现一个很棒的开源项目--程序员技能图谱.@Zhang Wei写的Java Software Engineer Skill Map确实能解答我心中的疑问.好的东西应该向更多的人,我将英文版本根据自己的理解写成中文版,并补充了相应的学习资料(书籍是可下载的,中文书籍可能存在版权问题,推荐书籍都是比较经典的英文教材).希望这次整理能帮助更多的人解答心中的疑惑.

Questioning the lambda architecure

https://www.oreilly.com/radar/questioning-the-lambda-architecture/ What is a Lambda Architecture and how do I become one? The Lambda Architecture looks something like this: The way this works is that an immutable sequence of records is captured and f

Spring Batch Hello World Example

Spring Batch is a framework for batch processing – execution of a series of jobs. In Spring Batch, A job consists of many steps and each step consists of a READ-PROCESS-WRITE task or single operation task (tasklet). For “READ-PROCESS-WRITE” process,

[Spring Batch 系列] 第一节 初识 Spring Batch

距离开始使用 Spring Batch 有一段时间了,一直没有时间整理,现在项目即将完结,整理下这段时间学习和使用经历. 官网地址:http://projects.spring.io/spring-batch/ 一.定义与特点 A lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operati