Get rid of "Potential deadlock detected" message while waiting for a signal

I am waiting for a signal but getting “Potential deadlock detected” error. Workflow is still running so I assume maybe something is not configured correctly.


@workflow.defn
class RequestDataWorkflow:
    def __init__(self) -> None:
        self._result = None

    @workflow.run
    async def run(self, params: RequestDataParams) -> RequestDataResult:
        activity_params = Params(
            to_email=params.email,
            first_name=params.first_name,
            last_name=params.tlast_name,
            sender_first_name=params.user_first_name,
            sender_last_name=params.user_last_name
        )

        activity_results = await workflow.execute_activity(
            send_email,
            activity_params,
            schedule_to_close_timeout=timedelta(seconds=5)
        )

        while True:
            if not (self._result is None):
                return RequestDataResult(
                    conversation_id=activity_results.conversation_id,
                    number=self._request_sin_workflow_result.number,
                    first_name=self._request_sin_workflow_result.first_name,
                    ast_name=self._request_sin_workflow_result.last_name,
                    middle_name=self._request_sin_workflow_result.middle_name
                )

    @workflow.signal(name="FORM_SUBMITTED")
    async def submit_greeting(self, res: RequestDataResult) -> None:
        self._result = res

That while loop is a busy loop that will block the event loop and block workflow progress. Consider changing to:

await workflow.wait_condition(lambda: self._result is not None)

Alternatively you can use asyncio.Queue like this example does to have the workflow function wait on a signal to set data

1 Like