Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seedlink and multi threads #561

Closed
sbonaime opened this issue Apr 29, 2013 · 5 comments
Closed

Seedlink and multi threads #561

sbonaime opened this issue Apr 29, 2013 · 5 comments
Labels
Milestone

Comments

@sbonaime
Copy link
Contributor

I have a problem when I use seedlink clients in threads.
Here is my code:

from obspy.seedlink.slclient import SLClient
import threading
from obspy.core.utcdatetime import UTCDateTime

if __name__ == '__main__':

    #the first SLClient()
    slClient_1 = SLClient(loglevel='DEBUG')
    slClient_1.slconn.setSLAddress("rtserver.ipgp.fr:18000")
    slClient_1.multiselect = ("G_SSB:BHN")
    dt = UTCDateTime()
    slClient_1.begin_time = (dt - 35000).formatSeedLink()
    print slClient_1.end_time
    slClient_1.verbose = 2
    slClient_1.initialize()

    #the second SLClient()
    slClient_2 = SLClient(loglevel='DEBUG')
    slClient_2.slconn.setSLAddress("rtserver.ipgp.fr:18000")
    slClient_2.multiselect =  ("G_TAM:BHZ")
    dt = UTCDateTime()
    slClient_2.begin_time = (dt - 35000).formatSeedLink()
    print slClient_2.end_time
    slClient_2.verbose = 2
    slClient_2.initialize()

    # start slClient_1 in a thread
    thread_1 = threading.Thread(target=slClient_1.run)
    thread_1.start()

    # start slClient_2 in a thread
    thread_2 = threading.Thread(target=slClient_2.run)
    thread_2.start()

With just one thread, I don't have any problem, but with at least two, I have the following errors and warnings

Warning: msr_unpack_steim2(G_SSB_10_BHN_D): number of samples indicated in header (408) does not equal data (406)
G_SSB_10_BHN_D: Warning: Data integrity check for Steim-2 failed, last_data=4077, xn=3199
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G SSB
Warning: msr_unpack_steim2(G_SSB_10_BHN_D): number of samples indicated in header (408) does not equal data (406)
G_SSB_10_BHN_D: Warning: Data integrity check for Steim-2 failed, last_data=4077, xn=3199

with Mac OS 10.6.8, latest obspy dev version, python 2.7.4

on linux Opensuse , python 2.7.4:

ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G TAM
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G TAM
G_TAM_00_BHZ_D: Warning: Data integrity check for Steim-2 failed, last_data=8217, xn=1149
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G TAM
G_TAM_00_BHZ_D: Warning: Data integrity check for Steim-2 failed, last_data=8217, xn=1149
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G TAM
G_TAM_00_BHZ_D: Warning: Data integrity check for Steim-2 failed, last_data=13628, xn=1149
G_TAM_00_BHZ_D: Warning: Data integrity check for Steim-2 failed, last_data=13628, xn=1149
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G SSB
G_TAM_00_BHZ_D: Warning: Data integrity check for Steim-2 failed, last_data=13628, xn=1149
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G TAM
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G SSB
Warning: msr_unpack_steim2(G_SSB_00_BHN_D): number of samples indicated in header (343) does not equal data (333)
G_SSB_00_BHN_D: Warning: Data integrity check for Steim-2 failed, last_data=272, xn=2212
ERROR: obspy.seedlink [rtserver.ipgp.fr:18000]:unexpected data received: G SSB
Warning: msr_unpack_steim2(G_SSB_00_BHN_D): number of samples indicated in header (343) does not equal data (333)
G_SSB_00_BHN_D: Warning: Data integrity check for Steim-2 failed, last_data=272, xn=2212
Warning: msr_unpack_steim2(G_SSB_00_BHN_D): number of samples indicated in header (343) does not equal data (333)

After the backtrace has been recovered, the errors seems to disappear. Most of the first paquets are corrupted and not usable

When I use two different seedlink server (not in the same place ), I have less errors and warnings.

Maybe the threads share the same receiving buffer which is maybe too small and/or not updated quickly enough

WIth just one thread I don't have any problem

@megies
Copy link
Member

megies commented Sep 1, 2013

I think it is usually not necessary to connect to one seedlink server with more than one thread. Fetching multiple stations/channels can be handled in one client (see also sbonaime/seedlink_plotter#6). If multiple clients in threads connecting to different servers is not a problem (as I understood), then fixing this / looking into it is probably pretty low priority.

@bmorg
Copy link
Contributor

bmorg commented Apr 7, 2014

Hi!

The anomalous thread behaviour is related to how the SeedLink connection object stores the retrieved data internally.

The data is stored in two bytearrays inside an SLState object (databuf and packed_buf). These bytearrays are however initialized as class attributes and hence shared between all instances of SLState (and thus SeedLinkConnection).

This is fixed in the commit referenced above.

@bonaime: Your code runs fine for me now. Can you confirm this with the fix_seedlink_multithread branch in my ObsPy fork?

@sbonaime
Copy link
Contributor Author

sbonaime commented Apr 7, 2014

Hi
@bmorg: Your fix runs fine with my code.
Thank you !

@bmorg
Copy link
Contributor

bmorg commented Apr 7, 2014

@bonaime: Thank you for testing. I opened a new pull request.

megies added a commit that referenced this issue Apr 7, 2014
Fixed obspy.seedlink bugs caused by mixed usage of class/instance attributes. Fixes #561.
@megies megies added the bug label Apr 7, 2014
@megies megies closed this as completed Apr 7, 2014
@megies
Copy link
Member

megies commented Apr 7, 2014

Fixed in #769.

@QuLogic QuLogic added this to the 0.9.2 milestone Jul 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants