Skip to content

Commit a0f1b7c

Browse files
start with concurrency
1 parent 975e0f4 commit a0f1b7c

8 files changed

+420
-0
lines changed

.editorconfig

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_size = 4
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.js]
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false
17+
18+
# 4 space indentation
19+
[*.py]
20+
indent_style = space
21+
indent_size = 4
22+
23+
# 4 space indentation
24+
[*.toml]
25+
indent_style = space
26+
indent_size = 2
27+
28+
# YAML Files
29+
[*.{yml,yaml}]
30+
indent_size = 2
31+
32+
[*.sh]
33+
indent_style = space
34+
indent_size = 2
35+
36+
[*.{json,tpl}]
37+
indent_style = space
38+
indent_size = 2

.gitignore

+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/git,macos,visualstudiocode,python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=git,macos,visualstudiocode,python
4+
5+
### Git ###
6+
# Created by git for backups. To disable backups in Git:
7+
# $ git config --global mergetool.keepBackup false
8+
*.orig
9+
10+
# Created by git when using merge tools for conflicts
11+
*.BACKUP.*
12+
*.BASE.*
13+
*.LOCAL.*
14+
*.REMOTE.*
15+
*_BACKUP_*.txt
16+
*_BASE_*.txt
17+
*_LOCAL_*.txt
18+
*_REMOTE_*.txt
19+
20+
### macOS ###
21+
# General
22+
.DS_Store
23+
.AppleDouble
24+
.LSOverride
25+
26+
# Icon must end with two \r
27+
Icon
28+
29+
30+
# Thumbnails
31+
._*
32+
33+
# Files that might appear in the root of a volume
34+
.DocumentRevisions-V100
35+
.fseventsd
36+
.Spotlight-V100
37+
.TemporaryItems
38+
.Trashes
39+
.VolumeIcon.icns
40+
.com.apple.timemachine.donotpresent
41+
42+
# Directories potentially created on remote AFP share
43+
.AppleDB
44+
.AppleDesktop
45+
Network Trash Folder
46+
Temporary Items
47+
.apdisk
48+
49+
### Python ###
50+
# Byte-compiled / optimized / DLL files
51+
__pycache__/
52+
*.py[cod]
53+
*$py.class
54+
55+
# C extensions
56+
*.so
57+
58+
# Distribution / packaging
59+
.Python
60+
build/
61+
develop-eggs/
62+
dist/
63+
downloads/
64+
eggs/
65+
.eggs/
66+
parts/
67+
sdist/
68+
var/
69+
wheels/
70+
pip-wheel-metadata/
71+
share/python-wheels/
72+
*.egg-info/
73+
.installed.cfg
74+
*.egg
75+
MANIFEST
76+
77+
# PyInstaller
78+
# Usually these files are written by a python script from a template
79+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
80+
*.manifest
81+
*.spec
82+
83+
# Installer logs
84+
pip-log.txt
85+
pip-delete-this-directory.txt
86+
87+
# Unit test / coverage reports
88+
htmlcov/
89+
.tox/
90+
.nox/
91+
.coverage
92+
.coverage.*
93+
.cache
94+
nosetests.xml
95+
coverage.xml
96+
*.cover
97+
*.py,cover
98+
.hypothesis/
99+
.pytest_cache/
100+
pytestdebug.log
101+
102+
# Translations
103+
*.mo
104+
*.pot
105+
106+
# Django stuff:
107+
*.log
108+
local_settings.py
109+
db.sqlite3
110+
db.sqlite3-journal
111+
112+
# Flask stuff:
113+
instance/
114+
.webassets-cache
115+
116+
# Scrapy stuff:
117+
.scrapy
118+
119+
# Sphinx documentation
120+
docs/_build/
121+
doc/_build/
122+
123+
# PyBuilder
124+
target/
125+
126+
# Jupyter Notebook
127+
.ipynb_checkpoints
128+
129+
# IPython
130+
profile_default/
131+
ipython_config.py
132+
133+
# pyenv
134+
.python-version
135+
136+
# pipenv
137+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
138+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
139+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
140+
# install all needed dependencies.
141+
#Pipfile.lock
142+
143+
# poetry
144+
#poetry.lock
145+
146+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
147+
__pypackages__/
148+
149+
# Celery stuff
150+
celerybeat-schedule
151+
celerybeat.pid
152+
153+
# SageMath parsed files
154+
*.sage.py
155+
156+
# Environments
157+
# .env
158+
.env/
159+
.venv/
160+
env/
161+
venv/
162+
ENV/
163+
env.bak/
164+
venv.bak/
165+
pythonenv*
166+
167+
# Spyder project settings
168+
.spyderproject
169+
.spyproject
170+
171+
# Rope project settings
172+
.ropeproject
173+
174+
# mkdocs documentation
175+
/site
176+
177+
# mypy
178+
.mypy_cache/
179+
.dmypy.json
180+
dmypy.json
181+
182+
# Pyre type checker
183+
.pyre/
184+
185+
# pytype static type analyzer
186+
.pytype/
187+
188+
# operating system-related files
189+
# file properties cache/storage on macOS
190+
*.DS_Store
191+
# thumbnail cache on Windows
192+
Thumbs.db
193+
194+
# profiling data
195+
.prof
196+
197+
198+
### VisualStudioCode ###
199+
.vscode/*
200+
!.vscode/settings.json
201+
!.vscode/tasks.json
202+
!.vscode/launch.json
203+
!.vscode/extensions.json
204+
*.code-workspace
205+
206+
### VisualStudioCode Patch ###
207+
# Ignore all local history of files
208+
.history
209+
.ionide
210+
211+
# End of https://www.toptal.com/developers/gitignore/api/git,macos,visualstudiocode,python

.pre-commit-config.yaml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-added-large-files
6+
args: ['--maxkb=5000']
7+
- id: check-ast
8+
- id: check-builtin-literals
9+
- id: check-case-conflict
10+
- id: check-docstring-first
11+
- id: check-executables-have-shebangs
12+
- id: check-json
13+
- id: check-merge-conflict
14+
- id: check-symlinks
15+
- id: check-toml
16+
- id: check-vcs-permalinks
17+
- id: check-xml
18+
- id: check-yaml
19+
- id: debug-statements
20+
- id: destroyed-symlinks
21+
- id: detect-aws-credentials
22+
args: ['--allow-missing-credentials']
23+
- id: detect-private-key
24+
- id: double-quote-string-fixer
25+
- id: end-of-file-fixer
26+
- id: fix-byte-order-marker
27+
- id: fix-encoding-pragma
28+
- id: mixed-line-ending
29+
args: ['--fix=lf']
30+
description: Forces to replace line ending by the UNIX 'lf' character.
31+
- id: pretty-format-json
32+
args: ['--autofix', '--no-sort-keys', '--indent=2']
33+
- id: requirements-txt-fixer
34+
- id: sort-simple-yaml
35+
- id: trailing-whitespace
36+
- repo: https://github.com/smian/pre-commit-makefile.git
37+
rev: 261f8fb4b31dfdc05d1a1d7fbde1f1462ecde66d
38+
hooks:
39+
- id: makefile-doc
40+
- repo: meta
41+
hooks:
42+
- id: check-useless-excludes
43+
- repo: https://github.com/gruntwork-io/pre-commit
44+
rev: v0.1.12 # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
45+
hooks:
46+
- id: shellcheck
47+
- repo: https://github.com/ambv/black
48+
rev: 19.10b0
49+
hooks:
50+
- id: black
51+
language_version: python3.8
52+
- repo: https://gitlab.com/pycqa/flake8
53+
rev: 3.9.2
54+
hooks:
55+
- id: flake8
56+
- repo: https://github.com/markdownlint/markdownlint
57+
rev: v0.11.0
58+
hooks:
59+
- id: markdownlint
60+
name: Markdownlint
61+
description: Run markdownlint on your Markdown files
62+
entry: mdl
63+
language: ruby
64+
files: \.(md|mdown|markdown)$
65+
- repo: https://github.com/adrienverge/yamllint.git
66+
rev: v1.24.2
67+
hooks:
68+
- id: yamllint
69+
files: \.(yaml|yml)$
70+
types: [file, yaml]
71+
entry: 'yamllint --strict -d "{extends: relaxed, rules: {line-length: {max: 200}}}"'
72+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
73+
rev: v5.0.0
74+
hooks:
75+
- id: commitlint
76+
stages: [commit-msg]
77+

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SHELL := /bin/bash
2+
.ONESHELL:
3+
.SHELLFLAGS := -eu -o pipefail -c
4+
MAKEFLAGS += --warn-undefined-variables
5+
MAKEFLAGS += --no-builtin-rules
6+
7+
help:
8+
@printf "Usage: make [target] [VARIABLE=value]\nTargets:\n"
9+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
10+
11+
hooks: ## Setup pre commit.
12+
@pre-commit install
13+
@pre-commit gc
14+
@pre-commit autoupdate
15+
16+
validate: ## Validate files with pre-commit hooks
17+
@pre-commit run --all-files

RESOURCES.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Threading
2+
3+
## [Python Concourency](https://realpython.com/python-concurrency)
4+
5+
- https://github.com/realpython/materials/tree/master/concurrency-overview
6+
7+
Concurrency Type | Switching Decision | Number of Processors
8+
| :---------------------------------:|:-----------------------------------------------------------------------|:----------------------------|
9+
Pre-emptive multitasking (threading) | The operating system decides when to switch tasks external to Python. | 1
10+
Cooperative multitasking (asyncio) | The tasks decide when to give up control. | 1
11+
Multiprocessing (multiprocessing) | The processes all run at the same time on different processors. | Many
12+
13+
Adding concurrency to your program adds extra code and complications, so you’ll need to decide if the potential speed up is worth the extra effort.
14+
15+
| I/O-Bound Process | CPU-Bound Process
16+
|:---------------------------|:-------------------------------------------------------|
17+
Your program spends most of its time talking to a slow device, like a network connection, a hard drive, or a printer. | You program spends most of its time doing CPU operations.
18+
Speeding it up involves overlapping the times spent waiting for these devices. | Speeding it up involves finding ways to do more computations in the same amount of time.
19+

concurency/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Concourency
2+

0 commit comments

Comments
 (0)