obspy / obspy

ObsPy: A Python Toolbox for seismology/seismological observatories.
https://www.obspy.org
Other
1.16k stars 535 forks source link

FDSN Client initialization error on import #1377

Closed trichter closed 8 years ago

trichter commented 8 years ago

Consider the following file data.py:

from obspy.clients.fdsn import Client
client = Client()

When I import with ìmport data python hangs here:

Python 2.7.11 |Anaconda 2.2.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import obspy; print obspy.__version__
1.0.1
>>> import data
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "data.py", line 2, in <module>
    client = Client()
  File "/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.py", line 281, in __init__
    self._discover_services()
  File "/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.py", line 1444, in _discover_services
    thread.join(15)
  File "/home/richter/anaconda/lib/python2.7/threading.py", line 951, in join
    self.__block.wait(delay)
  File "/home/richter/anaconda/lib/python2.7/threading.py", line 359, in wait
    _sleep(delay)
KeyboardInterrupt

Edit: After timeout (15s) this error pops up:

FDSNException                             Traceback (most recent call last)
<ipython-input-1-8e8046448a68> in <module>()
----> 1 import data

/home/richter/dev/playground/bugs/data.py in <module>()
      1 from obspy.clients.fdsn import Client
----> 2 client = Client()

/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.pyc in __init__(self, base_url, major_versions, user, password, user_agent, debug, timeout, service_mappings, force_redirect)
    279             print("Request Headers: %s" % str(self.request_headers))
    280 
--> 281         self._discover_services()
    282 
    283     def get_events(self, starttime=None, endtime=None, minlatitude=None,

/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.pyc in _discover_services(self)
   1496                    "be due to a temporary service outage or an invalid FDSN "
   1497                    "service address." % self.base_url)
-> 1498             raise FDSNException(msg)
   1499 
   1500         # Cache.

FDSNException: No FDSN services could be discovered at 'http://service.iris.edu'. This could be due to a temporary service outage or an invalid FDSN service address.

With debug=True in data.py python is not blocked by the error:

python -c "import data"

Base URL: http://service.iris.edu
Request Headers: {u'User-Agent': u'ObsPy 1.0.1 (Linux-3.13.0-85-generic-x86_64-with-debian-jessie-sid, Python 2.7.11)'}
Downloading http://service.iris.edu/fdsnws/dataselect/1/application.wadl with requesting gzip compression
Downloading http://service.iris.edu/fdsnws/event/1/application.wadl with requesting gzip compression
Downloading http://service.iris.edu/fdsnws/station/1/application.wadl with requesting gzip compression
Downloading http://service.iris.edu/fdsnws/event/1/catalogs with requesting gzip compression
Downloading http://service.iris.edu/fdsnws/event/1/contributors with requesting gzip compression
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "data.py", line 2, in <module>
    client = Client(debug=True)
  File "/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.py", line 281, in __init__
    self._discover_services()
  File "/home/richter/anaconda/lib/python2.7/site-packages/obspy/clients/fdsn/client.py", line 1498, in _discover_services
    raise FDSNException(msg)
obspy.clients.fdsn.header.FDSNException: No FDSN services could be discovered at 'http://service.iris.edu'. This could be due to a temporary service outage or an invalid FDSN service address.
Uncompressing gzipped response for http://service.iris.edu/fdsnws/event/1/contributors
Uncompressing gzipped response for http://service.iris.edu/fdsnws/station/1/application.wadl
Uncompressing gzipped response for http://service.iris.edu/fdsnws/dataselect/1/application.wadl
Uncompressing gzipped response for http://service.iris.edu/fdsnws/event/1/catalogs
Uncompressing gzipped response for http://service.iris.edu/fdsnws/event/1/application.wadl
Downloaded http://service.iris.edu/fdsnws/event/1/contributors with HTTP code: 200
Downloaded http://service.iris.edu/fdsnws/dataselect/1/application.wadl with HTTP code: 200
Downloaded http://service.iris.edu/fdsnws/event/1/catalogs with HTTP code: 200
Downloaded http://service.iris.edu/fdsnws/event/1/application.wadl with HTTP code: 200
Downloaded http://service.iris.edu/fdsnws/station/1/application.wadl with HTTP code: 200

python data.py is still working, of course.

trichter commented 8 years ago

Can anybody reproduce this issue?

megies commented 8 years ago

Can confirm, hangs for me as well.

krischer commented 8 years ago

I encountered this before: on Python 2 one cannot wait for a thread during an import, see 16.2.9 here: https://docs.python.org/2/library/threading.html#importing-in-threaded-code

On Python 3 it should work. The initialization routine of the client class launches a couple of threads to download the things in parallel.

trichter commented 8 years ago

Thanks for the explanation. For me it is OK to close the issue, just wanted to point at it. As you prefer.

krischer commented 8 years ago

I'm closing it - there is not a lot we can do here except removing the threading (much slower startup) or move to an async execution model (something we could think about but it would probably require an extra library).