Skip to content

gatttool timeout handler does not cleanup subprocesses #24

@haku

Description

@haku

The timeout handler in connection.wait_for_notification() (and other gatttool functions) does something like:

with Popen(cmd, shell=True, ...) as process:
    try:
        ...
    except TimeoutExpired:
        os.killpg(process.pid, signal.SIGINT)

Because its using shell=True it sends the SIGINT to the /bin/sh process instead of gatttool, which ignores it. The SIGINT needs to be sent directly to the gatttool process. Since the processes are not cleaned up, they build up over time. Often one of them might still have a lock on something, so all subsequent instances of gatttool fail.

This can be easily fixed by removing the shell=True and passing the arguments as a list. e.g.

cmd = ['gatttool', '--device', self._mac, ...]
with Popen(cmd, shell=True, ...) as process:
    ...

Then process.pid will be that of the gatttool process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions