From 2413a1691bf0f580201c2e85e324b25393b24031 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Tue, 10 Mar 2026 15:52:46 -0400 Subject: [PATCH 1/2] Make it non-`async def` --- hello/hello_standalone_activity.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hello/hello_standalone_activity.py b/hello/hello_standalone_activity.py index 541d687b..7d4be0e1 100644 --- a/hello/hello_standalone_activity.py +++ b/hello/hello_standalone_activity.py @@ -1,4 +1,5 @@ import asyncio +from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from datetime import timedelta @@ -21,7 +22,7 @@ class ComposeGreetingInput: # This is just a normal activity. You could invoke it from a workflow but, in this sample, we are # invoking it directly as a standalone activity. @activity.defn -async def compose_greeting(input: ComposeGreetingInput) -> str: +def compose_greeting(input: ComposeGreetingInput) -> str: activity.logger.info("Running activity with parameter %s" % input) return f"{input.greeting}, {input.name}!" @@ -68,6 +69,7 @@ async def main(): client, task_queue="hello-standalone-activity-task-queue", activities=[compose_greeting], + activity_executor=ThreadPoolExecutor(5), ): # While the worker is running, use the client to execute the activity. await my_client_code(client) From 591c5312c0e11cff2e97c26deb6ad83ed18036f7 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Tue, 10 Mar 2026 15:55:38 -0400 Subject: [PATCH 2/2] Add test --- tests/hello/hello_standalone_activity_test.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/hello/hello_standalone_activity_test.py diff --git a/tests/hello/hello_standalone_activity_test.py b/tests/hello/hello_standalone_activity_test.py new file mode 100644 index 00000000..0b322a8d --- /dev/null +++ b/tests/hello/hello_standalone_activity_test.py @@ -0,0 +1,29 @@ +import uuid +from concurrent.futures import ThreadPoolExecutor +from datetime import timedelta + +import pytest +from temporalio.client import Client +from temporalio.worker import Worker + +from hello.hello_standalone_activity import ComposeGreetingInput, compose_greeting + + +async def test_execute_standalone_activity(client: Client): + pytest.skip("Standalone Activity is not yet supported by the CLI dev server") + task_queue_name = str(uuid.uuid4()) + + async with Worker( + client, + task_queue=task_queue_name, + activities=[compose_greeting], + activity_executor=ThreadPoolExecutor(5), + ): + result = await client.execute_activity( + compose_greeting, + args=[ComposeGreetingInput("Hello", "World")], + id=str(uuid.uuid4()), + task_queue=task_queue_name, + start_to_close_timeout=timedelta(seconds=10), + ) + assert result == "Hello, World!"