# Segmentation Falut when num\_workers\>0 - requirements to Dataset?

**URL:** <https://discuss.pytorch.org/t/segmentation-falut-when-num-workers-0-requirements-to-dataset/34636>\
**Category:** Uncategorized\
**Created:** [January 14, 2019, 3:47pm UTC](https://discuss.pytorch.org/t/segmentation-falut-when-num-workers-0-requirements-to-dataset/34636 "2019-01-14T15:47:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max1](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/max1/32/8698_2.png) [@Max1](https://discuss.pytorch.org/u/Max1)\
**Post date:** [January 14, 2019, 3:47pm UTC](https://discuss.pytorch.org/t/segmentation-falut-when-num-workers-0-requirements-to-dataset/34636/1 "2019-01-14T15:47:07Z")

</div>

My `Dataset. __getitem__ ()` queries an external database every time when a sample is fetched. I didn’t expect it to work with `num_workers>=2`, but at least with `num_workers=1`, to let pytorch fetch the next batch while training the NN on the foregoing one (is that what `num_workers=1` does?). It fails even then with Segmentation Fault, so I’m using `num_workers=0` now.

Is there any trick that could help me? Like avoiding all calls to ` __getitem__ ()` (for e.g. doing data checks prior to training) and let torch alone call it during the training? Or maybe wrapping pieces in critical sections (no clue so far how to do it in python though).

I read [DataLoader, when num\_worker \>0, there is bug](https://discuss.pytorch.org/t/dataloader-when-num-worker-0-there-is-bug/25643/9?u=max1) but couldn’t find a workaround there. Used version: 1.0.0 py3.6\_cuda9.0.176\_cudnn7.4.1\_1
