Skip to content

Commit

Permalink
Merge dc1be88 into 16e41d9
Browse files Browse the repository at this point in the history
  • Loading branch information
rasup committed Feb 13, 2018
2 parents 16e41d9 + dc1be88 commit 15eef32
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- sudo chmod 0777 /var/run

install:
- pip install "coverage>=3.6" "nose>=1.3.0" "flake8>=2.1" "coveralls>=0.3"
- pip install "coverage>=3.6" "nose>=1.3.0" "flake8>=2.1" "coveralls>=0.3" "mock>=2.0.0"
- pip install -e .

script:
Expand Down
7 changes: 3 additions & 4 deletions pid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ def create(self):
try:
fcntl.flock(self.fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError as exc:
self.close(cleanup=False)
if self.allow_samepid:
return
raise PidFileAlreadyLockedError(exc)
if not self.allow_samepid:
self.close(cleanup=False)
raise PidFileAlreadyLockedError(exc)

check_result = self.check()
if check_result == PID_CHECK_SAMEPID:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path
import signal
from contextlib import contextmanager
from mock import patch

import pid

Expand Down Expand Up @@ -265,6 +266,23 @@ def test_pid_check_samepid():
pidfile.close()


def test_pid_check_samepid_two_processes():
pidfile_proc1 = pid.PidFile()
pidfile_proc2 = pid.PidFile(allow_samepid=True)

try:
with patch('pid.os.getpid') as mgetpid:
mgetpid.return_value = 1
pidfile_proc1.create()

mgetpid.return_value = 2
with raising(pid.PidFileAlreadyRunningError, pid.PidFileAlreadyLockedError):
pidfile_proc2.create()
finally:
pidfile_proc1.close()
pidfile_proc2.close()


def test_pid_default_term_signal():
signal.signal(signal.SIGTERM, signal.SIG_DFL)

Expand Down

0 comments on commit 15eef32

Please sign in to comment.