-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsched_test.py
More file actions
32 lines (24 loc) · 738 Bytes
/
sched_test.py
File metadata and controls
32 lines (24 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sched
import threading
import time
scheduler = sched.scheduler(time.time, time.sleep)
# Set up a global to be modified by the threads
counter = 0
def increment_counter(name):
global counter
print('EVENT:', time.time(), name)
counter += 1
print('NOW:', counter)
print('START:', time.time())
e1 = scheduler.enter(2, 1, increment_counter, ('E1',))
e2 = scheduler.enter(3, 1, increment_counter, ('E2',))
# Start a thread to run the events
t = threading.Thread(target=scheduler.run)
t.start()
# Back in the main thread, cancel the first scheduled event.
scheduler.cancel(e1)
# Wait for the scheduler to finish running in the thread
t.join()
print('FINAL:', counter)