analysiscenter / radio

RadIO is a library for data science research of computed tomography imaging
https://analysiscenter.github.io/radio/
Apache License 2.0
222 stars 52 forks source link

"Event Loop is already running" - inside Jupyter notebook #20

Closed johnny555 closed 5 years ago

johnny555 commented 6 years ago

Whenever I try and run a function that has a async decorator inside a jupyter notebook I get the following error: RuntimeError: This event loop is already running

What I'm trying to do is load a data file that I have dumped to disk in 'blosc' format. However it seems to give this event loop error when I run it using Jupyter notebook. If I run the same command in a python script it works fine.

Steps to reproduce:

1, Build a pipeline to dump files to disk in blosc format, and use it to dump the files. 2, Using Jupyter notebook, attempt to load in the data, something similar to:

data = FilesIndex(path=path+'/*', dirs=True)
batch_dumped = CITB(pe.create_subset(data.index[0 : 4]))
batch_dumped.load(fmt='blosc')

Expected output:

batch object to contain scan data.

Current output:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-16-1c87479e8aee> in <module>()
----> 1 batch_dumped.load(fmt='blosc')

/media/resonance/Data/PE/anaconda3/lib/python3.6/site-packages/radio/dataset/dataset/decorators.py in _action_wrapper(action_self, *args, **kwargs)
     35                 action_self.pipeline.get_variable(_lock_name).acquire()
     36 
---> 37         _res = action_method(action_self, *args, **kwargs)
     38 
     39         if _use_lock is not None:

/media/resonance/Data/PE/anaconda3/lib/python3.6/site-packages/radio/preprocessing/ct_batch.py in load(self, fmt, components, bounds, **kwargs)
    363             components = np.asarray(components).reshape(-1)
    364 
--> 365             self._load_blosc(components=components)              # pylint: disable=no-value-for-parameter
    366         elif fmt == 'raw':
    367             self._load_raw()                # pylint: disable=no-value-for-parameter

/media/resonance/Data/PE/anaconda3/lib/python3.6/site-packages/radio/dataset/dataset/decorators.py in wrapped_method(self, *args, **kwargs)
    234             """ Wrap a method in a required parallel engine """
    235             if asyncio.iscoroutinefunction(method) or target in ['async', 'a']:
--> 236                 return wrap_with_async(self, args, kwargs)
    237             elif target in ['threads', 't']:
    238                 return wrap_with_threads(self, args, kwargs)

/media/resonance/Data/PE/anaconda3/lib/python3.6/site-packages/radio/dataset/dataset/decorators.py in wrap_with_async(self, args, kwargs)
    209                 futures.append(asyncio.ensure_future(method(self, *margs, **mkwargs)))
    210 
--> 211             loop.run_until_complete(asyncio.gather(*futures, loop=loop, return_exceptions=True))
    212 
    213             return _call_post_fn(self, post_fn, futures, args, full_kwargs)

/media/resonance/Data/PE/anaconda3/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
    453         future.add_done_callback(_run_until_complete_cb)
    454         try:
--> 455             self.run_forever()
    456         except:
    457             if new_task and future.done() and not future.cancelled():

/media/resonance/Data/PE/anaconda3/lib/python3.6/asyncio/base_events.py in run_forever(self)
    407         self._check_closed()
    408         if self.is_running():
--> 409             raise RuntimeError('This event loop is already running')
    410         if events._get_running_loop() is not None:
    411             raise RuntimeError(

RuntimeError: This event loop is already running
roman-kh commented 5 years ago

Closing for inactivity