Skip to content

Commit

Permalink
Add pickle support to Butler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pim Schellart authored and Pim Schellart committed May 22, 2018
1 parent 3bd5259 commit b3ac2e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/lsst/daf/butler/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def __init__(self, config=None, collection=None, run=None):
if self.run is None:
self.run = self.registry.makeRun(runCollection)

def __reduce__(self):
"""Support pickling.
"""
return (Butler, (self.config, ))

def put(self, obj, datasetType, dataId, producer=None):
"""Store and register a dataset.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

import os
import unittest
<<<<<<< HEAD
from tempfile import TemporaryDirectory
=======
import pickle
>>>>>>> Add pickle support to Butler.

import lsst.utils.tests

Expand Down Expand Up @@ -159,6 +163,13 @@ def testMakeRepo(self):
self.assertIn("datastore.formatters", full)
self.assertNotIn("datastore.formatters", limited)

def testPickle(self):
"""Test pickle support.
"""
butler = Butler(self.configFile)
butlerOut = pickle.loads(pickle.dumps(butler))
self.assertIsInstance(butlerOut, Butler)


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit b3ac2e1

Please sign in to comment.