Skip to content

Commit 92bbdef

Browse files
async setup
1 parent 7804c96 commit 92bbdef

8 files changed

+402
-4
lines changed

.gitignore

+108-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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
2+
# Created by https://www.toptal.com/developers/gitignore/api/git,macos,python,visualstudiocode,jetbrains
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=git,macos,python,visualstudiocode,jetbrains
44

55
### Git ###
66
# Created by git for backups. To disable backups in Git:
@@ -17,6 +17,109 @@
1717
*_LOCAL_*.txt
1818
*_REMOTE_*.txt
1919

20+
### JetBrains ###
21+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
22+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
23+
24+
# User-specific stuff
25+
.idea/**/workspace.xml
26+
.idea/**/tasks.xml
27+
.idea/**/usage.statistics.xml
28+
.idea/**/dictionaries
29+
.idea/**/shelf
30+
31+
# Generated files
32+
.idea/**/contentModel.xml
33+
34+
# Sensitive or high-churn files
35+
.idea/**/dataSources/
36+
.idea/**/dataSources.ids
37+
.idea/**/dataSources.local.xml
38+
.idea/**/sqlDataSources.xml
39+
.idea/**/dynamic.xml
40+
.idea/**/uiDesigner.xml
41+
.idea/**/dbnavigator.xml
42+
43+
# Gradle
44+
.idea/**/gradle.xml
45+
.idea/**/libraries
46+
47+
# Gradle and Maven with auto-import
48+
# When using Gradle or Maven with auto-import, you should exclude module files,
49+
# since they will be recreated, and may cause churn. Uncomment if using
50+
# auto-import.
51+
# .idea/artifacts
52+
# .idea/compiler.xml
53+
# .idea/jarRepositories.xml
54+
# .idea/modules.xml
55+
# .idea/*.iml
56+
# .idea/modules
57+
# *.iml
58+
# *.ipr
59+
60+
# CMake
61+
cmake-build-*/
62+
63+
# Mongo Explorer plugin
64+
.idea/**/mongoSettings.xml
65+
66+
# File-based project format
67+
*.iws
68+
69+
# IntelliJ
70+
out/
71+
72+
# mpeltonen/sbt-idea plugin
73+
.idea_modules/
74+
75+
# JIRA plugin
76+
atlassian-ide-plugin.xml
77+
78+
# Cursive Clojure plugin
79+
.idea/replstate.xml
80+
81+
# Crashlytics plugin (for Android Studio and IntelliJ)
82+
com_crashlytics_export_strings.xml
83+
crashlytics.properties
84+
crashlytics-build.properties
85+
fabric.properties
86+
87+
# Editor-based Rest Client
88+
.idea/httpRequests
89+
90+
# Android studio 3.1+ serialized cache file
91+
.idea/caches/build_file_checksums.ser
92+
93+
### JetBrains Patch ###
94+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
95+
96+
# *.iml
97+
# modules.xml
98+
# .idea/misc.xml
99+
# *.ipr
100+
101+
# Sonarlint plugin
102+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
103+
.idea/**/sonarlint/
104+
105+
# SonarQube Plugin
106+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
107+
.idea/**/sonarIssues.xml
108+
109+
# Markdown Navigator plugin
110+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
111+
.idea/**/markdown-navigator.xml
112+
.idea/**/markdown-navigator-enh.xml
113+
.idea/**/markdown-navigator/
114+
115+
# Cache file creation bug
116+
# See https://youtrack.jetbrains.com/issue/JBR-2257
117+
.idea/$CACHE_FILE$
118+
119+
# CodeStream plugin
120+
# https://plugins.jetbrains.com/plugin/12206-codestream
121+
.idea/codestream.xml
122+
20123
### macOS ###
21124
# General
22125
.DS_Store
@@ -208,4 +311,6 @@ Thumbs.db
208311
.history
209312
.ionide
210313

211-
# End of https://www.toptal.com/developers/gitignore/api/git,macos,visualstudiocode,python
314+
# End of https://www.toptal.com/developers/gitignore/api/git,macos,python,visualstudiocode,jetbrains
315+
316+
.idea

Pipfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
aiohttp = "*"
8+
async-timeout = "*"
9+
async_generator = "*"
10+
11+
[dev-packages]
12+
13+
[requires]
14+
python_version = "3.10"

Pipfile.lock

+198
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

concurency/cio_threading.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
3+
import concurrent.futures
4+
import requests
5+
import threading
6+
import time
7+
8+
thread_local = threading.local()
9+
10+
def get_session():
11+
'''
12+
So each thread will create a single session the first time it calls get_session() and then will simply use that session on each subsequent call throughout its lifetime.
13+
'''
14+
if not hasattr(thread_local, "session"):
15+
thread_local.session = requests.Session()
16+
return thread_local.session
17+
18+
def get_counter():
19+
'''
20+
So each thread will create a single session the first time it calls get_session() and then will simply use that session on each subsequent call throughout its lifetime.
21+
'''
22+
if not hasattr(thread_local, "counter"):
23+
thread_local.counter = 0
24+
return thread_local.counter
25+
26+
def download_site(url):
27+
session = get_session()
28+
counter = get_counter()
29+
with session.get(url) as response:
30+
counter += 1
31+
print(f"status: {response.status_code}, content: {len(response.content)}, count: {counter}")
32+
33+
34+
def download_all_sites(sites):
35+
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
36+
executor.map(download_site, sites)
37+
38+
39+
if __name__ == "__main__":
40+
sites = [
41+
"https://www.jython.org",
42+
"http://olympus.realpython.org/dice",
43+
] * 80
44+
start_time = time.time()
45+
download_all_sites(sites)
46+
duration = time.time() - start_time
47+
print(f"Downloaded {len(sites)} in {duration} seconds")

concurency/generator.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# https://www.python.org/dev/peps/pep-0525/

0 commit comments

Comments
 (0)