-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobstest.py
39 lines (33 loc) · 918 Bytes
/
jobstest.py
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
33
34
35
36
37
38
39
import jobs
import time
import itertools
import pathlib
@jobs.OnResult(jobs.GetMimeType)
def OnResult(job, result):
if job.status == "exception":
raise result.exception
else:
print(f"{result.file}: {result.mime}")
pool = jobs.ThreadedJobPool(threads = 16)
for file in pathlib.Path("/usr/bin").iterdir():
job = jobs.GetMimeType(file)
#job.onresult = OnResult
pool.Add(job)
#job = jobs.ExceptionJob()
#job.onresult = OnResult
#pool.Add(job)
#pool.Join(i)
#pool.Add(i)
#result = pool.Join(i)
#pool.Close()
#raise Exception(f"{result.file}: {result.mime}")
for i in itertools.count():
print("Busy loop!")
jobsleft = len([x for x in pool.jobs if x.status == "running"])
if not jobsleft:
print("No jobs left, exiting...")
pool.Close()
raise SystemExit(0)
print(f"Jobs left: {jobsleft}")
print("Sleeping for 1 second...")
time.sleep(1)