GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - daggaz/python-multiprocessing-utils: Python multiprocessing utilities

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
multiprocessing_utils
multiprocessing_utils
 
 
.gitignore
.gitignore
 
 
LICENSE.txt
LICENSE.txt
 
 
MANIFEST.in
MANIFEST.in
 
 
README.rst
README.rst
 
 
requirements.txt
requirements.txt
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 
tox.ini
tox.ini
 
 

Repository files navigation

python-multiprocessing-utils

Multiprocessing utilities

Shared locks

"Shared" version of the standard Lock() and RLock() classes found in the multiprocessing/threading modules.

Shared locks can be acquired in two modes, shared and exclusive.

Any number of processes/threads can acquire the lock in shared mode.

Only one process/thread can acquire the lock in exclusive mode.

A process/thread attempting to exclusively acquire the lock will block until the lock has been released by all other threads/processes.

A process/thread attempting to shared acquire the lock will only block while there is an exclusive lock.

This is a little like database locks, which can be acquired for shared reading, or exclusive writing.

lock = multiprocessing_utils.SharedLock()

def exclusive_worker():
    with lock.exclusive():
        # this code will only run when no other
        # process/thread in a lock context

def shared_worker():
    with lock:
        # this code will run so long as no
        # thread/process holds an exclusive lock

multiprocess-safe threading.local()

A process (and thread) safe version of threading.local()

l = multiprocessing_utils.local()
l.x = 1

def f():
    try:
        print(l.x)
    except Attribute:
        print("x not set")
f()                                        # prints "1"
threading.Thread(target=f).start()         # prints "x not set"
multiprocessing.Process(target=f).start()  # prints "x not set"

Difference to standard threading.local()

A standard threading.local() instance created before forking (via os.fork() or multiprocessing.Process()) will be "local" as expected and the new process will have access to any data set before the fork.

Using a standard threading.local() in the example above would yield:

f()                                        # prints "1"
threading.Thread(target=f).start()         # prints "x not set"
multiprocessing.Process(target=f).start()  # prints "1" :(

About

Python multiprocessing utilities

pypi.python.org/pypi/multiprocessing-utils

Topics

multiprocessingpython

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.