Skip to content

Instantly share code, notes, and snippets.

@pdonorio
Created August 7, 2017 14:59
Show Gist options
  • Save pdonorio/06f334685ea4b3e9cbbe04527790c3c2 to your computer and use it in GitHub Desktop.
Save pdonorio/06f334685ea4b3e9cbbe04527790c3c2 to your computer and use it in GitHub Desktop.
Pickable iRODS session

Since iRODS uses thread locks I tried overriding the original session class to make it possible.

Test it with:

import pickle
import base64

original_session = iRODSPickleSession(...)

# serialize
serialized_session = base64.encodestring(pickle.dumps(original_session))
# recover
usable_session = pickle.loads(base64.decodestring(serialized_session))
# -*- coding: utf-8 -*-
"""
Allow to manipulate irods session as a string,
to be saved inside a database.
"""
from irods.pool import Pool
from irods.session import iRODSSession
class iRODSPickleSession(iRODSSession):
def __getstate__(self):
attrs = {}
for attr in self.__dict__:
obj = getattr(self, attr)
if attr == 'pool':
attrs['account'] = obj.account
attrs['timeout'] = obj.timeout
else:
attrs[attr] = obj
return attrs
def __setstate__(self, state):
for name, value in state.items():
# print(name, value)
setattr(self, name, value)
self.pool = Pool(state.get('account'), state.get('timeout'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment