PEP8 + Python exceptions

This commit is contained in:
Daniel Goldberg 2017-10-01 17:59:17 +03:00
parent b77aa5d10c
commit b668a0d0f3
1 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,8 @@
import sys
import ctypes
import logging
import sys
from abc import ABCMeta, abstractmethod
from config import WormConfiguration
__author__ = 'itamar'
@ -28,7 +29,7 @@ class _SystemSingleton(object):
class WindowsSystemSingleton(_SystemSingleton):
def __init__(self):
self._mutex_name = r"Global\%s" % (WormConfiguration.singleton_mutex_name, )
self._mutex_name = r"Global\%s" % (WormConfiguration.singleton_mutex_name,)
self._mutex_handle = None
@property
@ -53,7 +54,7 @@ class WindowsSystemSingleton(_SystemSingleton):
self._mutex_name)
return False
self._mutex_handle = handle
LOG.debug("Global singleton mutex %r acquired",
@ -79,16 +80,16 @@ class LinuxSystemSingleton(_SystemSingleton):
def try_lock(self):
assert self._sock_handle is None, "Singleton already locked"
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.bind('\0' + self._unix_sock_name)
except socket.error, e:
except socket.error as e:
LOG.error("Cannot acquire system singleton %r, error code %d, error: %s",
self._unix_sock_name, e.args[0], e.args[1])
return False
self._sock_handle = sock
LOG.debug("Global singleton mutex %r acquired", self._unix_sock_name)
@ -100,9 +101,12 @@ class LinuxSystemSingleton(_SystemSingleton):
self._sock_handle.close()
self._sock_handle = None
if sys.platform == "win32":
import winerror
SystemSingleton = WindowsSystemSingleton
else:
import socket
SystemSingleton = LinuxSystemSingleton