FZJ-INM1-BDA / siibra-python

Software interfaces for interacting with brain atlases - Python client
Apache License 2.0
48 stars 10 forks source link

Deal gracefully with connection problems to remote repositories #4

Closed marcenko closed 3 years ago

marcenko commented 3 years ago
Will retrieve a list of gene acronyms from Allen Atlas now.
This may take a minute.
Traceback (most recent call last):
   File "aioserver.py", line 25, in <module>
     import brainscapes
   File "/webjugex/brainscapes/brainscapes/__init__.py", line 24, in
<module>
     from .atlas import REGISTRY as atlases
   File "/webjugex/brainscapes/brainscapes/atlas.py", line 21, in <module>
     from . import parcellations, spaces, features, logger
   File "/webjugex/brainscapes/brainscapes/features/__init__.py", line
30, in <module>
     extractor_types,gene_names,modalities = __init__()
   File "/webjugex/brainscapes/brainscapes/features/__init__.py", line
22, in __init__
     from .genes import AllenBrainAtlasQuery
   File "/webjugex/brainscapes/brainscapes/features/genes.py", line 65,
in <module>
     class AllenBrainAtlasQuery(FeatureExtractor):
   File "/webjugex/brainscapes/brainscapes/features/genes.py", line 123,
in AllenBrainAtlasQuery
     +"This may take a minute."))
   File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
     return _default_decoder.decode(s)
   File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
     raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Happens quite seldom, but we should maybe catch the error if it happens.

---------- old comments --------- Dickscheid, Timo

This is a very general thing. How shall we deal with a situation where the remote repositories could not be reached? Brainscapes works offline with cached data, but without a network connection on initial setup it doesn't quite make sense to use brainscapes. To be discussed, any opinions?

To provide a suggestion, I would distinguish some cases:

  1. Remote configuration of brainscapes cannot be retrieved - fail with an exception, ask to check neetwork connection. No reasonable use of brainscapes will be possible.
  2. Retrieval of certain data features fails, as in this issue. I would print a warning about the problem but continue, with this feature type missing.

However, 2. has implications for the cache. We need to make sure we do not store an empty cache item that will be re-opened later on. If no cache item is generated, brainscapes will try to run the query again next time.

dickscheid commented 3 years ago

The gene names are now stored with the source code for efficiency.

skoehnen commented 3 years ago

The gene names are now stored with the source code for efficiency.

Hmm, not sure what you mean here. My understanding is that gene labels are subject to change, we shouldn't hard-code them.

dickscheid commented 3 years ago

If they change very frequently, we need to add them to the caching mechanism but remove them from the package loading sequence. If they change rarely, I still consider it a good solution to save them statically with the code. They are nonly used for autocompletion, so if the list is slightly outdated at times that's not really a problem, but we need to organize the maintenance. Do you have an estimate of the frequency of changes to the gene names?

dickscheid commented 3 years ago

should be adressed together with #22, will extend #22 and close this one.