GithubHelp home page GithubHelp logo

dark3d / python3-multiprocessing-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hevnsnt/python3-multiprocessing-template

0.0 0.0 0.0 24 KB

This is just an empty python3 multiprocessing template. I use it for things

Python 100.00%

python3-multiprocessing-template's Introduction

Python3 Multiprocessing, Argparse, and Version template

Description

This is just an empty python3 multiprocessing, argparse and python version testing template. It is my main framework for multi-threaded applications. It is to make startign multiprocessing scripts easy and fun.

It includes a lot of argparse examples that should cover pretty much whatever you are planning on doing.

Demo App

This contains a demo application that will read in a file and then do work on each line. Using the argparse examples given, if a argument --threads is not given, it will use all available CPU threads, which isnt always the best idea, but you do you...

Known Issues

CTRL-C works great in Linux, not exactly sure what is going on with windows (any help here would be appreciated) but if you need to break the program in windows, use CTRL-Break.

Some background

Map is a cool little function, and the key to easily injecting parallelism into your Python code. For those unfamiliar, map is something lifted from functional languages like Lisp. It is a function which maps another function over a sequence. e.g.

This single statement handles everything we did in the seven line build_worker_pool function from example2.py. Namely, It creates a bunch of available workers, starts them up so that they’re ready to do some work, and stores all of them in variable so that they’re easily accessed.

The pool objects take a few parameters, but for now, the only one worth noting is the first one: processes. This sets the number of workers in the pool. If you leave it blank, it will default to the number of Cores in your machine.

In the general case, if you’re using the multiprocessing pool for CPU bound tasks, more cores equals more speed (I say that with a lot of caveats). However, when threading and dealing with network bound stuff, things seem to vary wildly, so it’s a good idea to experiment with the exact size of the pool.

Sources:

https://www.ellicium.com/python-multiprocessing-pool-process/

https://chriskiehl.com/article/parallelism-in-one-line

python3-multiprocessing-template's People

Contributors

hevnsnt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.