Skip to content

Commit dbdb4a0

Browse files
committed
Update to v0.1.1
1 parent 9369e92 commit dbdb4a0

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

fsSignal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.1.1"
22
__doc__ = """
33
Signal capturer v{}
44
Copyright (C) 2021 Fusion Solutions KFT <contact@fusionsolutions.io>

fsSignal/abcs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Builtin modules
22
from __future__ import annotations
33
from abc import ABCMeta, abstractmethod
4-
from typing import Any, Iterable, Union
4+
from typing import Any, Iterable, Union, TypeVar
55
# Third party modules
66
# Local modules
77
# Program
8+
T = TypeVar("T")
9+
810
class T_Lock(metaclass=ABCMeta):
911
@abstractmethod
1012
def acquire(self, blocking:bool=..., timeout:float=...) -> bool: ...
@@ -55,7 +57,7 @@ def signalSoftKill(self, *args:Any, **kwargs:Any) -> None: ...
5557
@abstractmethod
5658
def signalHardKill(self, *args:Any, **kwargs:Any) -> None: ...
5759
@abstractmethod
58-
def iter(self, it:Iterable[Any], checkDelay:float=...) -> Iterable[Any]: ...
60+
def iter(self, it:Iterable[T], checkDelay:float=...) -> Iterable[T]: ...
5961
@abstractmethod
6062
def softKill(self) -> None: ...
6163
@abstractmethod

fsSignal/fsSignal.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
import traceback, signal as _signal
44
from threading import Event
55
from time import monotonic, sleep
6-
from typing import Callable, Dict, Any, Iterator, Iterable, Optional, Union, cast
6+
from typing import Callable, Dict, Iterator, Iterable, Optional, Union, Any, cast
77
# Third party modules
88
# Local modules
9-
from .abcs import T_Signal, T_Locker, T_Lock
9+
from .abcs import T_Signal, T_Locker, T_Lock, T
1010
# Program
1111
class KillSignal(Exception): pass
1212

13-
class SignalIterator(Iterator[Any]):
13+
class SignalIterator(Iterator[T]):
1414
__slots__ = ("event", "it", "checkDelay", "lastCheck")
1515
event:Event
16-
it:Iterator[Any]
16+
it:Iterator[T]
1717
checkDelay:float
1818
lastCheck:float
19-
def __init__(self, event:Event, it:Iterable[Any], checkDelay:float=1.0):
19+
def __init__(self, event:Event, it:Iterable[T], checkDelay:float=1.0):
2020
self.event = event
2121
self.it = it.__iter__()
2222
self.checkDelay = checkDelay
2323
self.lastCheck = monotonic()
24-
def __iter__(self) -> Iterator[Any]:
24+
def __iter__(self) -> Iterator[T]:
2525
return self
26-
def __next__(self) -> Any:
26+
def __next__(self) -> T:
2727
m = monotonic()
2828
if m-self.lastCheck > self.checkDelay:
2929
self.lastCheck = m
@@ -56,8 +56,9 @@ def locked(self) -> bool:
5656
self.lock.release()
5757
return False
5858
return True
59-
def __enter__(self) -> Any:
59+
def __enter__(self) -> ExtendedLocker:
6060
self.lock.acquire()
61+
return self
6162
def __exit__(self, type:Any, value:Any, traceback:Any) -> Any:
6263
self.lock.release()
6364

@@ -119,7 +120,7 @@ def signalSoftKill(self, *args:Any, **kwargs:Any) -> None:
119120
def signalHardKill(self, *args:Any, **kwargs:Any) -> None:
120121
if isinstance(Signal._handler, Signal):
121122
return Signal._handler._signalHardKill(*args, **kwargs)
122-
def iter(self, it:Iterable[Any], checkDelay:float=1.0) -> Iterable[Any]:
123+
def iter(self, it:Iterable[T], checkDelay:float=1.0) -> Iterable[T]:
123124
if isinstance(Signal._handler, Signal):
124125
return Signal._handler._iter(it, checkDelay, self._force)
125126
return it
@@ -201,7 +202,7 @@ def _sleep(self, seconds:Union[int, float], raiseOnKill:bool=False, force:bool=T
201202
if (self.eHard if force else self.eSoft).wait(float(seconds)) and raiseOnKill:
202203
raise KillSignal
203204
return None
204-
def _iter(self, it:Iterable[Any], checkDelay:float=1.0, force:bool=True) -> Iterator[Any]:
205+
def _iter(self, it:Iterable[T], checkDelay:float=1.0, force:bool=True) -> Iterator[T]:
205206
return SignalIterator(self.eHard if force else self.eSoft, it, checkDelay)
206207
def _warpLock(self, lock:Any, force:bool=True) -> T_Locker:
207208
return SignalLocker(self.eHard if force else self.eSoft, cast(T_Lock, lock))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name = "python-fssignal",
12-
version = "0.1.0",
12+
version = "0.1.1",
1313
description = "Signal capturer",
1414
keywords = "signal capture utility fusion solutions fusionsolutions",
1515
author = "Andor `iFA` Rajci - Fusions Solutions KFT",

0 commit comments

Comments
 (0)