MCPcopy Create free account
hub / github.com/ActiveState/code / worker

Function worker

recipes/Python/475160_TaskQueue/recipe-475160.py:61–73  ·  view source on GitHub ↗

Stop at 1; otherwise if odd then load 3*x+1; or if even then divide by two

()

Source from the content-addressed store, hash-verified

59import sys
60
61def worker():
62 'Stop at 1; otherwise if odd then load 3*x+1; or if even then divide by two'
63 name = threading.currentThread().getName()
64 while True:
65 x = q.get()
66 sys.stdout.write('%s\t%d\n' % (name, x))
67 if x <= 1:
68 sys.stdout.write('!\n')
69 elif x % 2 == 1:
70 q.put(x * 3 + 1)
71 else:
72 q.put(x // 2)
73 q.task_done()
74
75q = TaskQueue()
76numworkers = 4

Callers

nothing calls this directly

Calls 5

getNameMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
putMethod · 0.45
task_doneMethod · 0.45

Tested by

no test coverage detected