Skip to content

Allow PrimitiveJob to use Python processes rather than threads in _submit. #12989

@kshyatt-aws

Description

@kshyatt-aws

What should we add?

In primitive_job.py:

def _submit(self):
        if self._future is not None:
            raise JobError("Primitive job has been submitted already.")

        executor = ThreadPoolExecutor(max_workers=1)  # pylint: disable=consider-using-with
        self._future = executor.submit(self._function, *self._args, **self._kwargs)
        executor.shutdown(wait=False)

Any backend that's using PrimitiveJob is locked into using Python's threading, which can cause locks when interacting with other non-Python languages with their own thread schedulers. Python processes don't have this problem (because they avoid the GIL). This behaviour is currently blocking me when using a custom backend I've written. It'd be great if the PrimitiveJob could obey the preference set in the QISKIT_PARALLEL environment variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions