Zeth - Zerocash on Ethereum
0.8
Reference implementation of the Zeth protocol by Clearmatics
mpc
coordinator
interval.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
3
# Copyright (c) 2015-2022 Clearmatics Technologies Ltd
4
#
5
# SPDX-License-Identifier: LGPL-3.0+
6
7
import
time
8
from
threading
import
Condition, Thread
9
from
typing
import
Callable
10
11
12
class
Interval
:
13
"""
14
Simple thread that periodically executes a callback (in a thread).
15
"""
16
def
__init__
(self, period: float, callback: Callable[[],
None
]):
17
self.
period
= period
18
self.
callback
= callback
19
self.
next_deadline
= time.time()
20
self.
running
=
True
21
self.
condition
= Condition()
22
self.
thread
= Thread(target=self.
_thread
)
23
self.
thread
.start()
24
25
def
stop
(self) -> None:
26
self.
running
=
False
27
self.
condition
.acquire()
28
self.
condition
.notify()
29
self.
condition
.release()
30
self.
thread
.join()
31
32
def
_thread(self) -> None:
33
while
self.
running
:
34
self.
callback
()
35
self.
next_deadline
= self.
next_deadline
+ self.
period
36
37
self.
condition
.acquire()
38
while
self.
running
:
39
now = time.time()
40
if
now >= self.
next_deadline
:
41
break
42
self.
condition
.
wait
(self.
next_deadline
- now)
coordinator.interval.Interval._thread
None _thread(self)
Definition:
interval.py:32
coordinator.interval.Interval
Definition:
interval.py:12
coordinator.interval.Interval.period
period
Definition:
interval.py:17
coordinator.interval.Interval.next_deadline
next_deadline
Definition:
interval.py:19
coordinator.interval.Interval.callback
callback
Definition:
interval.py:18
coordinator.interval.Interval.condition
condition
Definition:
interval.py:21
coordinator.interval.Interval.thread
thread
Definition:
interval.py:22
zeth.cli.zeth_wait.wait
None wait(Context ctx, str transaction_id)
Definition:
zeth_wait.py:13
coordinator.interval.Interval.running
running
Definition:
interval.py:20
coordinator.interval.Interval.__init__
def __init__(self, float period, Callable[[], None] callback)
Definition:
interval.py:16
coordinator.interval.Interval.stop
None stop(self)
Definition:
interval.py:25
Generated on Mon Nov 28 2022 10:29:03 for Zeth - Zerocash on Ethereum by
1.8.17