Skip to content

Commit f7aec85

Browse files
Outro for concurrency (#14)
1 parent 2e1d11d commit f7aec85

File tree

12 files changed

+1226
-2
lines changed

12 files changed

+1226
-2
lines changed

Cargo.lock

Lines changed: 983 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Wrapping up
2+
3+
You should now have a strong theoretical foundation to reason about your options whenever
4+
you have a Python problem that could benefit from a concurrent solution.
5+
6+
That's only the beginning, though. To truly master conccurent programming, you need to practice it!\
7+
This wasn't the right venue to cover all the possible concurrency patterns you can express with Rust.
8+
Luckily enough, there's plenty of resources available to help you on that side! We recommend, in particular,
9+
the ["Threads" chapter](https://rust-exercises.com/100-exercises/07_threads/00_intro.html) of our own
10+
Rust course. It follows the same hands-on approach we've been using in this book, and it's a great way to
11+
get more practice with Rust's concurrency primitives.
12+
13+
Take the final exercise as a capstone project: you'll have to design a non-trivial algorithm and piece together
14+
various concurrenty primitives to implement a solution that's both correct and efficient. Don't shy
15+
away from the challenge: embrace it, it's the best way to learn!
16+
17+
## Beyond performance
18+
19+
A note, in closing: writing **correct** concurrent code is tricky.\
20+
We highlighted Rust, in this chapter, as a way to circumvent the limitations of Python's GIL and ultimately
21+
improve the performance of your code. But that's only half of the story.\
22+
Rust's type system and ownership model make it much easier to write concurrent code that's correct, too.
23+
As you delve deeper into the world of concurrent programming, you'll come to appreciate the real value of Rust's
24+
`Send` and `Sync` traits, which we've only briefly touched upon when discussing data races.
25+
26+
As the saying goes: people come to Rust for the performance, but they stay for its safety and correctness guarantees.

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
- [Releasing the GIL](03_concurrency/03_releasing_the_gil.md)
2424
- [Minimize GIL locking](03_concurrency/04_minimize_gil_locking.md)
2525
- [Immutable types](03_concurrency/05_immutable_types.md)
26+
- [Outro](03_concurrency/06_outro.md)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "outro3"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
crossbeam = "0.8"
11+
pyo3 = { workspace = true }
12+
scraper = "0.22"
13+
ureq = "2"
14+
url = "2"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["maturin>=1.8,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "outro3"
7+
requires-python = ">=3.13"
8+
classifiers = [
9+
"Programming Language :: Rust",
10+
"Programming Language :: Python :: Implementation :: CPython",
11+
"Programming Language :: Python :: Implementation :: PyPy",
12+
]
13+
version = "0.1.0"
14+
15+
[tool.maturin]
16+
features = ["pyo3/extension-module"]
17+
18+
[tool.uv]
19+
cache-keys = ["pyproject.toml", "Cargo.toml", "src/*.rs"]
20+
21+
[tool.uv.sources]
22+
outro3 = { workspace = true }
23+
24+
[tool.uv.workspace]
25+
members = ["sample"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# python generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# venv
10+
.venv

exercises/03_concurrency/06_outro/sample/README.md

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[project]
2+
name = "outro3_sample"
3+
version = "0.1.0"
4+
dependencies = ["outro3"]
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
8+
[build-system]
9+
requires = ["hatchling"]
10+
build-backend = "hatchling.build"
11+
12+
[dependency-groups]
13+
dev = ["pytest>=8.2.2"]
14+
15+
[tool.hatch.metadata]
16+
allow-direct-references = true
17+
18+
[tool.hatch.build.targets.wheel]
19+
packages = ["src/sample"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Modify the Rust extension to get the test below to pass
2+
# Do NOT modify the test itself!
3+
import pytest
4+
5+
from outro3 import site_map
6+
7+
def test_site_map():
8+
discovered_urls = set()
9+
site_map("https://rust-exercises.com", discovered_urls)
10+
assert len(discovered_urls) >= 200

0 commit comments

Comments
 (0)