[obspy-users] easyseedlink questions

Bernhard Morgenstern mail at bmorg.io
Sun Aug 7 21:27:54 CEST 2016

Hi Nikos,

I'm guessing you have you seen the corresponding chapter in the tutorial

> As far as I understand the on_data() function is running on a loop after
> the call of run() function. How am I suppose to close() the connection?

As I see it there is currently no convenient way to break the loop from
the client. You do have access to the underlying SeedLinkConnection
object through client.conn though, so calling the connection's
terminate() method from another thread should also terminate the run()
loop and trigger the on_terminate() callback:


> How can I also use the on_seedlink_error() and the on_terminate()? Could
> you provide me a very simple example like this one
> (https://docs.obspy.org/packages/autogen/obspy.clients.seedlink.easyseedlink.EasySeedLinkClient.html#obspy.clients.seedlink.easyseedlink.EasySeedLinkClient)?

The two methods provide callbacks for when either the SLTERMINATE or the
SLERROR packets were received. You can check the source of the
EasySeedLinkClient class [2] to see that they get called without any
arguments. So here is an extended example:

class MyClient(EasySeedLinkClient):

    def on_data(self, trace):
        print('Received trace:')

    def on_terminate(self):
        print('Terminated. Doing some kind of cleanup or reconnect...')

    def on_seedlink_error(self):
        # inspect self.conn or self.conn.state or ...

Hope that helps,

[1] https://docs.obspy.org/tutorial/code_snippets/easyseedlink.html

More information about the obspy-users mailing list