Skip to content

Commit

Permalink
Pass download lock between xdist workers
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoRoth committed Apr 18, 2018
1 parent 00b8314 commit 8befa6e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions oggm/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import multiprocessing as mp
from oggm import cfg, utils
import pickle

class OggmMpLockPlugin():
def pytest_configure(config):
if hasattr(config, 'workerinput'):
utils.lock = pickle.loads(config.workerinput['shared_lock'])
cfg.unpack_config(pickle.loads(config.workerinput['shared_cfg']))
else:
config.shared_lock = mp.Manager().Lock()
config.shared_cfg = cfg.pack_config()

def pytest_configure_node(node):
node.workerinput['shared_lock'] = pickle.dumps(node.config.shared_lock)
node.workerinput['shared_cfg'] = pickle.dumps(node.config.shared_cfg)

def pytest_configure(config):
if config.pluginmanager.hasplugin('xdist'):
config.pluginmanager.register(OggmMpLockPlugin())

0 comments on commit 8befa6e

Please sign in to comment.