# Issue with multiprocessing semaphore tracking

**URL:** <https://discuss.pytorch.org/t/issue-with-multiprocessing-semaphore-tracking/22943>\
**Category:** Uncategorized\
**Created:** [August 12, 2018, 2:10am UTC](https://discuss.pytorch.org/t/issue-with-multiprocessing-semaphore-tracking/22943 "2018-08-12T02:10:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![sbelharbi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@sbelharbi](https://discuss.pytorch.org/u/sbelharbi)\
**Post date:** [January 9, 2019, 4:57pm UTC](https://discuss.pytorch.org/t/issue-with-multiprocessing-semaphore-tracking/22943/4 "2019-01-09T16:57:26Z")

</div>

I run to the same issue with the warning (when running some preprocessing on GPU), except for now, I didn’t see a slow down in the running time of the code, yet.

```bash
python3.7/multiprocessing/semaphore_tracker.py:144: UserWarning: semaphore_tracker: There appear to be 1 leaked semaphores to clean up at shutdown
  len(cache))

```

The message seems harmful, but pretty annoying since it is displayed whenever the multiprocessing takes place.

One way to hide this warning is to ignore it using the Python module `warnings`. Also, redirecting the `stderr` may be temporary solution.

However, [`warnings.filterwarnings()`](https://docs.python.org/3/library/warnings.html#warnings.filterwarnings) DOES not work for this particular warning (and probably for all the warnings of the Python module `multiprocessing.semaphor_tracker()`. I don’t really understand why. I tried different ways using regular expressions, but nothing seem to work.

**Things that work** :

1. `python -W ignore your_script.py` --\> ignore ALL the warnings within your script. (not recommended).
2. `python -W ignore:semaphore_tracker:UserWarning your_script.py` or `python -W 'ignore:semaphore_tracker:UserWarning' your_script.py` seem to ignore exactly the above warning. It can also done by using the environment variable [PYTHONWARNINGS](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONWARNINGS):

```bash
export PYTHONWARNINGS='ignore:semaphore_tracker:UserWarning'

python your_script.py

```

Python 3.7.1, Pytorch 1.0.0.

---

_[View the full topic](https://discuss.pytorch.org/t/issue-with-multiprocessing-semaphore-tracking/22943)._
