initial commit (ready for pypi)
This commit is contained in:
parent
c4fd5eace6
commit
062b7933a2
4
MANIFEST
Normal file
4
MANIFEST
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# file GENERATED by distutils, do NOT edit
|
||||||
|
setup.cfg
|
||||||
|
setup.py
|
||||||
|
seppuku/__init__.py
|
@ -1,2 +1,6 @@
|
|||||||
# asyncio-seppuku
|
# asyncio-seppuku
|
||||||
sends signal to current pid after specified delay
|
sends signal to current pid after specified delay
|
||||||
|
|
||||||
|
## Usage:
|
||||||
|
See examples/simple.py
|
||||||
|
|
||||||
|
21
examples/simple.py
Normal file
21
examples/simple.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import asyncio
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from seppuku import killme_after
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
start_time = datetime.now()
|
||||||
|
print('Started')
|
||||||
|
|
||||||
|
killme_after(2, loop)
|
||||||
|
try:
|
||||||
|
loop.run_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('KeyboardInterrupt after {}'.format(datetime.now() - start_time))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
17
seppuku/__init__.py
Normal file
17
seppuku/__init__.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import os, signal
|
||||||
|
|
||||||
|
|
||||||
|
def killme_after(delay, loop, sig='SIGINT', pid=None):
|
||||||
|
"""
|
||||||
|
:param delay: delay in seconds to execute signal
|
||||||
|
:param loop: asyncio event loop
|
||||||
|
:param sig: signal (string), must presents in signal package
|
||||||
|
:param pid: PID (default is current PID)
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if not hasattr(signal, sig):
|
||||||
|
print('unknown signal "%s"' % sig)
|
||||||
|
else:
|
||||||
|
if not getattr(loop, 'sig_%s' % sig, False):
|
||||||
|
loop.call_later(delay, os.kill, pid or os.getpid(), getattr(signal, sig))
|
||||||
|
setattr(loop, 'sig_%s' % sig, True)
|
20
setup.py
Normal file
20
setup.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='asyncio-seppuku',
|
||||||
|
packages=['seppuku'],
|
||||||
|
version='0.1.0',
|
||||||
|
description='Sending kill signal after specified delay',
|
||||||
|
author='jar3b',
|
||||||
|
author_email='hellotan@live.ru',
|
||||||
|
url='https://github.com/jar3b/asyncio-seppuku',
|
||||||
|
download_url='https://github.com/jar3b/asyncio-seppuku/archive/0.1.0.tar.gz',
|
||||||
|
keywords='asyncio signal python3',
|
||||||
|
classifiers=[
|
||||||
|
'Development Status :: 3 - Alpha',
|
||||||
|
'License :: OSI Approved :: MIT License',
|
||||||
|
'Programming Language :: Python :: 3.4',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
|
'Programming Language :: Python :: 3.6',
|
||||||
|
],
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user