Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indigo_renderer segfault in multithreaded context (1.5.0) #476

Closed
flc opened this issue Sep 1, 2021 · 3 comments
Closed

indigo_renderer segfault in multithreaded context (1.5.0) #476

flc opened this issue Sep 1, 2021 · 3 comments

Comments

@flc
Copy link

flc commented Sep 1, 2021

Hi,

The segmentation fault can be reproduced with the following code:

import concurrent.futures
import indigo
from indigo import renderer as indigo_renderer

SMILES_LIST = [
    'C',
    'CC',
    'CCC',
    'CCCCC',
    'CCCCCC',
    'CCCCCCC',
    'CCCCCCCC',
]

def render(smiles):
    ind = indigo.Indigo()
    imol = ind.loadMolecule(smiles)
    renderer = indigo_renderer.IndigoRenderer(ind)
    ind.setOption('render-output-format', 'png')
    buff = renderer.renderToBuffer(imol)
    return buff.tobytes()

with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
    futures_dict = {
        executor.submit(render, smiles): smiles
        for smiles in SMILES_LIST
    }
    for future in concurrent.futures.as_completed(futures_dict):
        smi = futures_dict[future]
        try:
            data = future.result()
        except Exception as exc:
            print(exc)
        else:
            print(data)
$ PYTHONFAULTHANDLER=1 python indigo_threading_test.py
Fatal Python error: Segmentation fault

Thread 0x00007fd2bbfff700 (most recent call first):
  File "/home/f/virtualenvs/so2/lib/python3.8/site-packages/indigo/renderer.py", line 77 in renderToBuffer
  File "indigo_threading_test.py", line 20 in render
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57 in run
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 80 in _worker
  File "/usr/lib/python3.8/threading.py", line 870 in run
  File "/usr/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/usr/lib/python3.8/threading.py", line 890 in _bootstrap

Current thread 0x00007fd2c0973700 (most recent call first):
  File "/home/f/.virtualenvs/so2/lib/python3.8/site-packages/indigo/renderer.py", line 77 in renderToBuffer
  File "indigo_threading_test.py", line 20 in render
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57 in run
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 80 in _worker
  File "/usr/lib/python3.8/threading.py", line 870 in run
  File "/usr/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/usr/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x00007fd2c275f740 (most recent call first):
  File "/usr/lib/python3.8/threading.py", line 302 in wait
  File "/usr/lib/python3.8/threading.py", line 558 in wait
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 244 in as_completed
  File "indigo_threading_test.py", line 28 in <module>
Segmentation fault

No segfault if:

  • ThreadPoolExecutor.max_workers=1
  • indigo 1.4.3 is used
  • only Indigo is used and the IndigoRenderer is not used

The segfault still occurs if:

  • global Indigo and/or IndigoRenderer instance is used and not initialized inside the function

Python version:
Python 3.8.11

Indigo version:
1.5.0-g1aef03cac-x86_64-linux-gnu-9.3.1

@even1024
Copy link
Collaborator

@flc , we are working on the issue. Will fix it soon.

@even1024
Copy link
Collaborator

even1024 commented Sep 16, 2021

Fixed with PR: #489

@mkviatkovskii
Copy link
Member

Dear @flc,
We have fixed the problem. I'll inform you when new version with fix appears in public repositories. I expect it to happen before the end of the week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants