ogrisel: > For the future, should we do the same as in joblib and run the test of joblib as part of the CI?

I agree but let's do that in another PR.
diff --git a/loky/backend/semaphore_tracker.py b/loky/backend/semaphore_tracker.py
index 79587f2..f494237 100644
--- a/loky/backend/semaphore_tracker.py
+++ b/loky/backend/semaphore_tracker.py
@@ -203,7 +203,6 @@ def main(fd):
                 try:
                     sem_unlink(name)
                     if VERBOSE:  # pragma: no cover
-                        name = name.decode('ascii')
                         sys.stderr.write("[SemaphoreTracker] unlink {}\n"
                                          .format(name))
                         sys.stderr.flush()
diff --git a/loky/backend/semlock.py b/loky/backend/semlock.py
index c94c4cd..2d35f6a 100644
--- a/loky/backend/semlock.py
+++ b/loky/backend/semlock.py
@@ -68,7 +68,7 @@ if sys.version_info[:2] < (3, 3):
 
 
 def sem_unlink(name):
-    if pthread.sem_unlink(name) < 0:
+    if pthread.sem_unlink(name.encode('ascii')) < 0:
         raiseFromErrno()
 
 
@@ -153,8 +153,8 @@ class SemLock(object):
         self.ident = 0
         self.kind = kind
         self.maxvalue = maxvalue
-        self.name = name.encode('ascii')
-        self.handle = _sem_open(self.name, value)
+        self.name = name
+        self.handle = _sem_open(self.name.encode('ascii'), value)
 
     def __del__(self):
         try:
@@ -265,7 +265,7 @@ class SemLock(object):
         self.kind = kind
         self.maxvalue = maxvalue
         self.name = name
-        self.handle = _sem_open(name)
+        self.handle = _sem_open(name.encode('ascii'))
         return self
 
 
diff --git a/loky/backend/synchronize.py b/loky/backend/synchronize.py
index 2cdb43d..4773b9d 100644
--- a/loky/backend/synchronize.py
+++ b/loky/backend/synchronize.py
@@ -121,8 +121,7 @@ class SemLock(object):
     @staticmethod
     def _make_name():
         # OSX does not support long names for semaphores
-        name = '/loky-%i-%s' % (os.getpid(), next(SemLock._rand))
-        return name
+        return '/loky-%i-%s' % (os.getpid(), next(SemLock._rand))
 
 
 #

loky.backend.semaphore_tracker.sem_unlink does not have same signature if coming from ctypes or _multiprocessing
* `_multi_processing.sem_unlink` takes `str`
* `loky.backend.semlock.sem_unlink` comes from `ctypes` and take `bytes`.

It feels like some code was written with the ctypes variant in mind and raise an error when the `_multiprocessing.sem_unlink` is called. Tests seem to be only testing `loky.backend.semlock.sem_unlink`.

#### Context
This is an error I just saw in a joblib Travis [build](https://travis-ci.org/joblib/joblib/jobs/346847911#L4044). Note this is with loky version 1.2.1.

```
E               /home/travis/build/joblib/joblib/joblib/externals/loky/backend/semaphore_tracker.py:195: UserWarning: semaphore_tracker: There appear to be 6 leaked semaphores to clean up at shutdown
E                 len(cache))
E               /home/travis/build/joblib/joblib/joblib/externals/loky/backend/semaphore_tracker.py:211: UserWarning: semaphore_tracker: b'/loky-5456-6haleho6': TypeError('argument 1 must be str, not bytes',)
E                 warnings.warn('semaphore_tracker: %r: %r' % (name, e)) 
```
Quickly looking at it, it seems like this is still in master. The code where the warning happens is here:
 https://github.com/tomMoral/loky/blob/dec1c8144b12938dfe7bfc511009e12f25fd1cd9/loky/backend/semaphore_tracker.py#L203-L211


diff --git a/tests/test_synchronize.py b/tests/test_synchronize.py
index 797070d..4794f17 100644
--- a/tests/test_synchronize.py
+++ b/tests/test_synchronize.py
@@ -22,7 +22,7 @@ if sys.version_info < (3, 3):
 @pytest.mark.skipif(sys.platform == "win32", reason="UNIX test")
 def test_semlock_failure():
     from loky.backend.semlock import SemLock, sem_unlink
-    name = "test1"
+    name = "loky-test-semlock"
     sl = SemLock(0, 1, 1, name=name)
 
     with pytest.raises(FileExistsError):
@@ -30,7 +30,7 @@ def test_semlock_failure():
     sem_unlink(sl.name)
 
     with pytest.raises(FileNotFoundError):
-        SemLock._rebuild(None, 0, 0, name.encode('ascii'))
+        SemLock._rebuild(None, 0, 0, name)
 
 
 def assert_sem_value_equal(sem, value):

pip install -e .
parse_log_pytest
pytest
pytest psutil pytest-timeout coverage
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
cloudpickle==2.2.1
coverage==6.2
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/tomMoral/loky.git@7e46ee602a23251f476312357c00fd13f77f9938#egg=loky
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
psutil==7.0.0
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytest-timeout==2.1.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: loky
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cloudpickle==2.2.1
      - coverage==6.2
      - psutil==7.0.0
      - pytest-timeout==2.1.0
prefix: /opt/conda/envs/loky

tests/test_synchronize.py::test_semlock_failure
tests/test_synchronize.py::TestLock::test_lock tests/test_synchronize.py::TestLock::test_rlock tests/test_synchronize.py::TestLock::test_lock_context tests/test_synchronize.py::TestSemaphore::test_semaphore tests/test_synchronize.py::TestSemaphore::test_bounded_semaphore tests/test_synchronize.py::TestSemaphore::test_timeout tests/test_synchronize.py::TestCondition::test_notify tests/test_synchronize.py::TestCondition::test_notify_all tests/test_synchronize.py::TestCondition::test_timeout tests/test_synchronize.py::TestCondition::test_waitfor tests/test_synchronize.py::TestCondition::test_wait_result tests/test_synchronize.py::TestEvent::test_event
loky/backend/semaphore_tracker.py loky/backend/semlock.py loky/backend/synchronize.py
loky/backend/semaphore_tracker.py loky/backend/semlock.py loky/backend/synchronize.py