-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some terst plus uses events to await results instead of spinlocks
- Loading branch information
1 parent
f6b7828
commit 9d46f29
Showing
7 changed files
with
103 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
|
||
from tentacule.process_pool import ProcessPool | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def pool(): | ||
pool = ProcessPool(workers=3) | ||
try: | ||
pool.start() | ||
yield pool | ||
finally: | ||
pool.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def subtract(a: int, b: int): | ||
return a - b |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from tests.depency import subtract | ||
|
||
|
||
def simple_function(): | ||
return 5 | ||
|
||
|
||
def test_simple_function(pool): | ||
task_id = pool.new_task(simple_function) | ||
|
||
assert pool.get_result(task_id) == 5 | ||
|
||
|
||
def add(a: int, b: int): | ||
return a + b | ||
|
||
|
||
def test_simple_function_with_args(pool): | ||
task_id = pool.new_task(add, 6, 7) | ||
|
||
assert pool.get_result(task_id) == 13 | ||
|
||
|
||
def test_simple_function_with_kwargs(pool): | ||
task_id = pool.new_task(add, a=5, b=5) | ||
|
||
assert pool.get_result(task_id) == 10 | ||
|
||
|
||
def default_a(a: int = 0): | ||
return a | ||
|
||
|
||
def test_simple_function_with_default(pool): | ||
task_id = pool.new_task(default_a) | ||
assert pool.get_result(task_id) == 0 | ||
|
||
task_id = pool.new_task(default_a, 80) | ||
assert pool.get_result(task_id) == 80 | ||
|
||
|
||
def recurse(a: int = 0): | ||
if a == 10: | ||
return a | ||
return recurse(a + 1) | ||
|
||
|
||
def test_recursive(pool): | ||
task_id = pool.new_task(recurse) | ||
assert pool.get_result(task_id) == 10 | ||
|
||
|
||
def dependency_subtract(a: int, b: int): | ||
return subtract(a, b) | ||
|
||
|
||
def test_function_with_dependency(pool): | ||
task_id = pool.new_task(dependency_subtract, 7, 2) | ||
assert pool.get_result(task_id) == 5 |