audeering / opensmile

The Munich Open-Source Large-Scale Multimedia Feature Extractor

Home Page:https://audeering.github.io/opensmile/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for multi-threading

frankenjoe opened this issue · comments

When processing files using multiple threads in pyopensmile it fails with:

opensmile.core.SMILEapi.OpenSmileException: Code: 6

Would be nice if we could make SMILEapi thread-safe.

Does this happen every time when you attempt to use multiple threads or only sometimes? Does it happen with only specific config files? What would be the best approach to reproduce it?

In general, the SMILEapi should be fully thread-safe as long as you only use separate instances in each thread.

@chausner-audeering I have also encountered this issue when trying to use multiple threads with the python library. It seems to occur randomly, which might indicate some kind of race condition. But I have found the issue with all of the standard configs and the IS13 config I adapted.

I have some test code below which is hopefully reproducible.

from threading import Thread

import numpy as np
import opensmile

signals = np.random.random_sample(size=(2, 80000)).astype(np.float32)

def test(i):
    smile = opensmile.Smile(logfile=f"smile_{i}.log")
    smile(signals[i], 16000)
    del smile

threads = [Thread(target=test, args=(i,)) for i in range(2)]
for t in threads:
    t.start()
for t in threads:
    t.join()

When I run this code, it sometimes suceeds, sometimes fails with a segmentation fault, and sometimes raises the "Code 6" exception mentioned above. Sometimes the error occurs during Smile initialisation and other times it occurs during processing a signal.

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "test.py", line 10, in test
    smile = opensmile.Smile(logfile=f"smile_{i}.log")
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/audobject/core/decorator.py", line 109, in wrapper
    func(self, *args, **kwargs)
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/audeer/core/utils.py", line 174, in new_func
    return func(*args, **kwargs)
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/opensmile/core/smile.py", line 173, in __init__
    self._feature_names(),
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/opensmile/core/smile.py", line 333, in _feature_names
    smile = self._smile(options=options)
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/opensmile/core/smile.py", line 424, in _smile
    smile.initialize(
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/opensmile/core/SMILEapi.py", line 240, in initialize
    self._check_smile_result(smileapi.smile_initialize(self._smileobj,
  File "/home/akee511/src/emotion/.venv/lib/python3.8/site-packages/opensmile/core/SMILEapi.py", line 478, in _check_smile_result
    raise OpenSmileException(result)
opensmile.core.SMILEapi.OpenSmileException: Code: 6

When looking at the log files, one of them produces no errors but the other produces the error:

[ 26.11.2021 - 17:18:09 ]
    (ERR) [1] configManager: ConfigType::findFieldH: referenced base field with name 'Extremes.max' not found!
[ 26.11.2021 - 17:18:09 ]
    (ERR) [1] configManager: (line 29) cFileConfigReader::getInstance: unknown field type (name 'Extremes.max') (in ConfigType 'cFunctionals') ty=-1

smile_0.log
smile_1.log

@agkphysics Thanks a lot, that's very useful information.

We have solved this issue in an internal version and will publish a patch release in January that will include this fix.

Version 3.0.1 has been released with the fix.