RECETOX / MSMetaEnhancer

Tool for mass spectra metadata annotation.
https://msmetaenhancer.readthedocs.io/
MIT License
8 stars 9 forks source link

RunTimeError when running the example script #116

Closed chryswoods closed 2 years ago

chryswoods commented 2 years ago

Hi, I've tried running the example script from the website and get a RunTimeError. I get this if I run the script directly (e.g. python script.py) or when I try to run this interactively via ipython. I've copied the ipython session below so that you can see what is going on;

In [1]: import asyncio

In [2]: from MSMetaEnhancer import Application

In [3]: app = Application()

In [4]: app.load_spectra('tests/test_data/sample.msp', file_format='msp')
2022-07-07 16:01:16,538:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.
2022-07-07 16:01:16,539:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.
2022-07-07 16:01:16,539:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.

In [5]: app.curate_spectra() 

In [6]: services = ['CTS', 'CIR', 'NLM', 'IDSM', 'PubChem', 'BridgeDB', 'RDKit']

In [7]: jobs = [('name', 'inchi', 'IDSM'), ('inchi', 'formula', 'IDSM'), ('inchi', 'inchikey', 'IDSM'),
   ...:         ('inchi', 'iupac_name', 'IDSM'), ('inchi', 'canonical_smiles', 'IDSM')]

In [8]: asyncio.run(app.annotate_spectra(services, jobs))

In [9]: asyncio.run(app.annotate_spectra(services))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 asyncio.run(app.annotate_spectra(services))

File ~/joss_mamba/envs/MSMetaEnhancer/lib/python3.8/asyncio/runners.py:44, in run(main, debug)
     42     if debug is not None:
     43         loop.set_debug(debug)
---> 44     return loop.run_until_complete(main)
     45 finally:
     46     try:

File ~/joss_mamba/envs/MSMetaEnhancer/lib/python3.8/asyncio/base_events.py:616, in BaseEventLoop.run_until_complete(self, future)
    613 if not future.done():
    614     raise RuntimeError('Event loop stopped before Future completed.')
--> 616 return future.result()

File ~/MSMetaEnhancer/MSMetaEnhancer/app.py:76, in Application.annotate_spectra(self, converters, jobs, repeat, monitor, annotator)
     74 # start converters status checker and wait for first status
     75 try:
---> 76     monitor.start()
     77     monitor.first_check.wait()
     79     # create all possible jobs if not given

File ~/joss_mamba/envs/MSMetaEnhancer/lib/python3.8/threading.py:848, in Thread.start(self)
    845     raise RuntimeError("thread.__init__() not called")
    847 if self._started.is_set():
--> 848     raise RuntimeError("threads can only be started once")
    849 with _active_limbo_lock:
    850     _limbo[self] = self

RuntimeError: threads can only be started once

This is running on Linux (RHEL 7.9) in a Python 3.8 environment created as described in the instructions. Aside the from the test failure I reported in #112, all of the other unit tests pass.

I'm happy to give more information about my system if needed :-)

xtrojak commented 2 years ago

Thank you for pointing this out @chryswoods. The Application.annotate_spectra is actually meant to be run only once, so the code in README was misleading. I removed the code in #117, where you can also find more details.