Skip to content

Commit 5c1301b

Browse files
authored
Running ReactPy in a backhaul thread (#163)
- The entirety of the ReactPy rendering stack is encapsulated within a single backhaul thread. - Backhaul thread can be disabled via settings.py:REACTPY_BACKHAUL_THREAD - Implementation is "thread-safe" since all ReactPy code runs on the exact same thread.
1 parent 0aaaaac commit 5c1301b

30 files changed

+751
-109
lines changed

.github/workflows/test-docs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ jobs:
3333
pip install -r requirements/check-style.txt
3434
mypy --show-error-codes docs/python/
3535
black docs/python/ --check
36-
isort docs/python/ --check-only
37-
flake8 docs/python/
36+
ruff check docs/python/

.github/workflows/test-src.yml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
name: Test
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
10-
schedule:
11-
- cron: "0 0 * * *"
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: "0 0 * * *"
1212

1313
jobs:
14-
source:
15-
runs-on: ubuntu-latest
16-
strategy:
17-
matrix:
18-
python-version: ["3.8", "3.9", "3.10"]
19-
steps:
20-
- uses: actions/checkout@v3
21-
- uses: nanasess/setup-chromedriver@master
22-
- uses: actions/setup-node@v3
23-
with:
24-
node-version: "14"
25-
- name: Use Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v4
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
- name: Install Python Dependencies
30-
run: pip install -r requirements/test-run.txt
31-
- name: Run Tests
32-
run: |
33-
npm install -g npm@latest
34-
npm --version
35-
nox -s test
14+
source:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.9", "3.10", "3.11"]
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: nanasess/setup-chromedriver@master
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: "14"
25+
- name: Use Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
- name: Install Python Dependencies
30+
run: pip install -r requirements/test-run.txt
31+
- name: Run Tests
32+
run: |
33+
npm install -g npm@latest
34+
npm --version
35+
nox -s test

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ Using the following categories, list your changes in this order:
3434

3535
## [Unreleased]
3636

37-
- Nothing yet!
37+
### Added
38+
39+
- `REACTPY_BACKHAUL_THREAD` setting to enable/disable threading behavior.
40+
41+
### Changed
42+
43+
- By default, ReactPy will now use a backhaul thread to increase performance.
44+
- Minimum Python version required is now `3.9`
3845

3946
## [3.2.1] - 2023-06-29
4047

docs/python/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
# 2. You are using Django's `AUTHENTICATION_BACKENDS` setting and...
2121
# 3. Your Django user model does not define a `backend` attribute
2222
REACTPY_AUTH_BACKEND = None
23+
24+
# Whether to enable rendering ReactPy via a dedicated backhaul thread
25+
# This allows the webserver to process traffic while during ReactPy rendering
26+
REACTPY_BACKHAUL_THREAD = True

docs/src/contribute/code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
If you plan to make code changes to this repository, you will need to install the following dependencies first:
1414

15-
- [Python 3.8+](https://www.python.org/downloads/)
15+
- [Python 3.9+](https://www.python.org/downloads/)
1616
- [Git](https://git-scm.com/downloads)
1717
- [NPM](https://docs.npmjs.com/try-the-latest-stable-version-of-npm) for installing and managing Javascript
1818

docs/src/contribute/docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
If you plan to make changes to this documentation, you will need to install the following dependencies first:
1010

11-
- [Python 3.8+](https://www.python.org/downloads/)
11+
- [Python 3.9+](https://www.python.org/downloads/)
1212
- [Git](https://git-scm.com/downloads)
1313

1414
Once done, you should clone this repository:

docs/src/contribute/running-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This repository uses [Nox](https://nox.thea.codes/en/stable/) to run tests. For
1010

1111
If you plan to run tests, you will need to install the following dependencies first:
1212

13-
- [Python 3.8+](https://www.python.org/downloads/)
13+
- [Python 3.9+](https://www.python.org/downloads/)
1414
- [Git](https://git-scm.com/downloads)
1515

1616
Once done, you should clone this repository:

docs/src/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ backends
3535
backend
3636
frontend
3737
frontends
38+
backhaul

noxfile.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import nox
77
from nox.sessions import Session
88

9-
109
HERE = Path(__file__).parent
1110
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
1211

@@ -21,14 +20,6 @@ def manage(session: Session) -> None:
2120
session.run("python", "manage.py", *session.posargs)
2221

2322

24-
@nox.session(reuse_venv=True)
25-
def format(session: Session) -> None:
26-
"""Run automatic code formatters"""
27-
install_requirements_file(session, "check-style")
28-
session.run("black", ".")
29-
session.run("isort", ".")
30-
31-
3223
@nox.session
3324
def test(session: Session) -> None:
3425
"""Run the complete test suite"""
@@ -70,15 +61,14 @@ def test_types(session: Session) -> None:
7061
def test_style(session: Session) -> None:
7162
"""Check that style guidelines are being followed"""
7263
install_requirements_file(session, "check-style")
73-
session.run("flake8", "src/reactpy_django", "tests")
7464
session.run(
7565
"black",
7666
".",
7767
"--check",
7868
"--extend-exclude",
7969
"/migrations/",
8070
)
81-
session.run("isort", ".", "--check-only")
71+
session.run("ruff", "check", ".")
8272

8373

8474
def install_requirements_file(session: Session, name: str) -> None:

pyproject.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
requires = ["setuptools>=42", "wheel"]
33
build-backend = "setuptools.build_meta"
44

5-
[tool.isort]
6-
multi_line_output = 3
7-
force_grid_wrap = 0
8-
use_parentheses = "True"
9-
ensure_newline_before_comments = "True"
10-
include_trailing_comma = "True"
11-
line_length = 88
12-
lines_after_imports = 2
13-
extend_skip_glob = ["*/migrations/*", '.nox/*', '.venv/*', 'build/*']
14-
155
[tool.mypy]
166
exclude = [
177
'migrations/.*',
@@ -22,3 +12,11 @@ warn_redundant_casts = true
2212
warn_unused_ignores = true
2313
check_untyped_defs = true
2414
incremental = false
15+
16+
[tool.ruff.isort]
17+
known-first-party = ["src", "tests"]
18+
19+
[tool.ruff]
20+
ignore = ["E501"]
21+
extend-exclude = ["*/migrations/*", ".venv/*", ".eggs/*", ".nox/*", "build/*"]
22+
line-length = 120

0 commit comments

Comments
 (0)