Skip to content

Commit

Permalink
Merge pull request #769 from bmorg/fix_seedlink_multithread
Browse files Browse the repository at this point in the history
Fixed obspy.seedlink bugs caused by mixed usage of class/instance attributes. Fixes #561.
  • Loading branch information
megies committed Apr 7, 2014
2 parents b2f2746 + f8f9b4c commit 2954dab
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -19,6 +19,9 @@
specified explicitely (see #754)
- obspy.imaging:
* Fixing waveform plotting.
- obspy.seedlink:
* bugfix: different instances of a SeedLink connection had a shared
state (see #561)
- obspy.station:
* some bugfixes in the obspy.station object classes (see #710)
- obspy.taup:
Expand Down
9 changes: 4 additions & 5 deletions obspy/seedlink/client/slnetstation.py
Expand Up @@ -33,11 +33,6 @@ class SLNetStation(object):
:type btime: TTT
"""
MAX_SELECTOR_SIZE = 8
net = None
station = None
selectors = []
seqnum = -1
btime = None

def __init__(self, net, station, selectors, seqnum, timestamp):
"""
Expand All @@ -56,9 +51,13 @@ def __init__(self, net, station, selectors, seqnum, timestamp):
#print "DEBUG: selectors:", selectors
if selectors is not None:
self.selectors = selectors
else:
self.selectors = []
self.seqnum = seqnum
if timestamp is not None:
self.btime = UTCDateTime(timestamp)
else:
self.btime = None

def appendSelectors(self, newSelectors):
"""
Expand Down
35 changes: 16 additions & 19 deletions obspy/seedlink/client/slstate.py
Expand Up @@ -69,23 +69,23 @@ class SLState(object):
KEEP_ALIVE_QUERY = 2
BUFSIZE = 8192

state = SL_DOWN
query_mode = NO_QUERY
#AJL databuf = [str() for __idx0 in range(BUFSIZE)]
databuf = bytearray(BUFSIZE)
recptr = 0
sendptr = 0
expect_info = False
netto_trig = -1
netdly_trig = 0
keepalive_trig = -1
previous_time = 0.0
netto_time = 0.0
netdly_time = 0.0
keepalive_time = 0.0

def __init__(self):
pass
self.state = SLState.SL_DOWN
self.query_mode = SLState.NO_QUERY
#AJL self.databuf = [str() for __idx0 in range(BUFSIZE)]
self.databuf = bytearray(SLState.BUFSIZE)
#AJL packed_buf = [str() for __idx0 in range(BUFSIZE)]
self.packed_buf = bytearray(SLState.BUFSIZE)
self.recptr = 0
self.sendptr = 0
self.expect_info = False
self.netto_trig = -1
self.netdly_trig = 0
self.keepalive_trig = -1
self.previous_time = 0.0
self.netto_time = 0.0
self.netdly_time = 0.0
self.keepalive_time = 0.0

def getPacket(self):
"""
Expand Down Expand Up @@ -176,9 +176,6 @@ def incrementSendPointer(self):
"""
self.sendptr += SLPacket.SLHEADSIZE + SLPacket.SLRECSIZE

#AJL packed_buf = [str() for __idx0 in range(BUFSIZE)]
packed_buf = bytearray(BUFSIZE)

def packDataBuffer(self):
"""
Packs the buffer by removing all sent packets and shifting remaining
Expand Down
7 changes: 1 addition & 6 deletions obspy/seedlink/slpacket.py
Expand Up @@ -52,8 +52,6 @@ class SLPacket(object):
:type slhead: bytes
:var msrecord: The MiniSEED record.
:type msrecord: bytes
:var blockette: The Blockette contained in msrecord.
:type blockette: list
"""
TYPE_SLINFT = -101
TYPE_SLINF = -102
Expand All @@ -66,10 +64,6 @@ class SLPacket(object):
INFOSIGNATURE = "SLINFO"
ERRORSIGNATURE = "ERROR\r\n"
ENDSIGNATURE = "END"
slhead = None
msrecord = None
blockette = None
trace = None

def __init__(self, bytes=None, offset=None):
if bytes is None or offset is None:
Expand All @@ -80,6 +74,7 @@ def __init__(self, bytes=None, offset=None):
self.slhead = bytes[offset: offset + self.SLHEADSIZE]
self.msrecord = bytes[offset + self.SLHEADSIZE:
offset + self.SLHEADSIZE + self.SLRECSIZE]
self.trace = None

def getSequenceNumber(self):
#print "DEBUG: repr(self.slhead):", repr(self.slhead)
Expand Down
30 changes: 30 additions & 0 deletions obspy/seedlink/tests/test_slnetstation.py
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
The obspy.seedlink.client.slnetstation test suite.
"""
from obspy.seedlink.client.slnetstation import SLNetStation
import unittest


class SLNetStationTestCase(unittest.TestCase):

def test_issue769(self):
"""
Assure that different station objects don't share selector lists.
"""
station1 = SLNetStation('', '', None, -1, None)
station2 = SLNetStation('', '', None, -1, None)

station1.appendSelectors('FOO')

self.assertNotEqual(id(station1.selectors), id(station2.selectors))
self.assertEqual(station1.getSelectors(), ['FOO'])
self.assertEqual(station2.getSelectors(), [])


def suite():
return unittest.makeSuite(SLNetStationTestCase, 'test')


if __name__ == '__main__':
unittest.main(defaultTest='suite')
28 changes: 28 additions & 0 deletions obspy/seedlink/tests/test_slstate.py
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
The obspy.seedlink.client.slstate test suite.
"""
from obspy.core.util.decorator import skipIf
from obspy.seedlink.client.slstate import SLState
import unittest


class SLStateTestCase(unittest.TestCase):

def test_issue561(self):
"""
Assure that different state objects don't share data buffers.
"""
slstate1 = SLState()
slstate2 = SLState()

self.assertNotEqual(id(slstate1.databuf), id(slstate2.databuf))
self.assertNotEqual(id(slstate1.packed_buf), id(slstate2.packed_buf))


def suite():
return unittest.makeSuite(SLStateTestCase, 'test')


if __name__ == '__main__':
unittest.main(defaultTest='suite')

0 comments on commit 2954dab

Please sign in to comment.