https://github.com/tgalal/zyklus
A simple extensible event loop for python
https://github.com/tgalal/zyklus
Last synced: 13 days ago
JSON representation
A simple extensible event loop for python
- Host: GitHub
- URL: https://github.com/tgalal/zyklus
- Owner: tgalal
- License: mit
- Created: 2018-01-21T16:01:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-21T16:23:07.000Z (over 7 years ago)
- Last Synced: 2025-04-21T05:07:49.812Z (about 1 month ago)
- Language: Python
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zyklus
A simple event loop for executing functions within the loop's thread.
## Usage
### Current thread
```python
from zyklus import Zyklusdef output(what):
print(what)zyklus = Zyklus()
zyklus.post(lambda: output(1))
zyklus.post(lambda: output(2))
zyklus.post(lambda: output(3))
zyklus.post_delayed(lambda: output(5), 1)
zyklus.post(lambda: output(4))
zyklus.post_delayed(zyklus.terminate, 1.1)zyklus.loop()
output("done")
```
output:
```
1
2
3
4
5
done
```
### In background```python
from zyklus import Zyklus
import threadingdef output(what):
print(what)zyklus = Zyklus()
zyklusThread = threading.Thread(target=zyklus.loop)
zyklusThread.start()zyklus.post(lambda: output(1))
zyklus.post(lambda: output(2))
zyklus.post(lambda: output(3))
zyklus.post_delayed(lambda: output(5), 1)
zyklus.post(lambda: output(4))
zyklus.post_delayed(zyklus.terminate, 1.5)zyklusThread.join()
output("done")
```
output:
```
1
2
3
4
5
done
```## Installation
```
pip install zyklus
```