Skip to main content

GILBypass (GILB) is a module that allows you to bypass the Global Interpreter Lock (GIL) in Python.

Project description

GILBypass (GILB) is a python package that allows you to bypass the Global Interpreter Lock (GIL) in Python. GILB stands for Global Interpreter Lock Bypass. The GIL makes it so that only one thread can run at a time. This is a problem for programs that are CPU bound, because they can't use multiple cores. GILB allows you to bypass the GIL and use multiple cores.

Installation:

pip install GILBypass

Import as:

import GILB

Example program:

from GILB import bypass

if __name__ == '__main__':
    bypass('file.py', 10, gilb_chunk='chunk', gilb_global='global', gilb_header='header', gilb_footer='footer')

In this example, the file 'file.py' will be run using 10 processes. The file looks like this:

# global
import time
# global

# header
import time
start = time.time()
# header

# footer
end = time.time() - start
print("Finished in", end, "seconds.")
# footer

time.sleep(1)
print("1 Finished Sleeping")
# chunk
time.sleep(1)
print("2 Finished Sleeping")
# chunk
time.sleep(1)
print("3 Finished Sleeping")
# chunk
time.sleep(1)
print("4 Finished Sleeping")
# chunk
time.sleep(1)
print("5 Finished Sleeping")
# chunk
time.sleep(1)
print("6 Finished Sleeping")
# chunk
time.sleep(1)
print("7 Finished Sleeping")

The output is the following:

1 Finished Sleeping
Finished in 1.0006422996520996 seconds.
2 Finished Sleeping
Finished in 1.000640630722046 seconds.
4 Finished Sleeping
Finished in 1.0006122589111328 seconds.
5 Finished Sleeping
Finished in 1.0001180171966553 seconds.
6 Finished Sleeping
Finished in 1.000612497329712 seconds.
7 Finished Sleeping
Finished in 1.000640630722046 seconds.
3 Finished Sleeping
Finished in 1.000584363937378 seconds.

Note that it can be in another order. This is because the processes are running at the same time. Global is code that every process can access. It is run in every process, so the processes don't share globals. Header is code that is at the top of the execution. It is run once in every process. Footer is code that is at the bottom of the execution. It is run once in every process.

NOTE: The 'global' cannot access the 'header' or 'footer'. The 'header' and 'footer' cannot access the 'global'. The 'footer' can access the 'header'.


All the parameters for GILB.bypass() are:

  • file: Relative or absolute path to the file to be run.
  • processes: The amount of processes to run. If the amount of chunks is smaller than the amount of processes, processes=len(chunks). Defaults to multiprocessing.cpu_count()
  • executor: The function to execute the code. Defaults to pythons built-in 'exec'.
  • gilb_global: Name for the global tag. Defaults to 'gilb:global'
  • gilb_chunk: Name for the global tag. Defaults to 'gilb:chunk'
  • gilb_header: Name for the global tag. Defaults to 'gilb:header'
  • gilb_footer: Name for the global tag. Defaults to 'gilb:footer'

Ideas

  • Have some kind of return value.
  • Be able to bypass the file without a special syntax.
  • Make it possible to have a shared resource, that all processes can access.
  • Make it possible to use the file as a module (import it and use its functions).

For more functionality, visit the GitHub.

Changelog

0.1.0 (09/06/2023)

  • First Release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GILBypass-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file GILBypass-0.1.0.tar.gz.

File metadata

  • Download URL: GILBypass-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for GILBypass-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6916af1e55ea103e58f42782f32775706619fc03ad6fc833acce4de535da9d64
MD5 da79cfdbd208d1df9e3e44bf2a63edb7
BLAKE2b-256 168cd0feb6498163cdafb527490f42804e9cd6a0b3a2ec99b32e55c70497f218

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page