I have a problem using Twisted for simple concurrency in python. The problem is that I do not know how to do this, and all online resources relate to the capabilities of the Twisted Network. So I turn to the SO guru for some guidance.
Used Python 2.5.
A simplified version of my problem works as follows:
- A bunch of scientific evidence
- A function that iterates over data and creates output
- ??? <concurrency is introduced here, it takes pieces of data from 1 and passes it to 2
- Exit from 3 is combined and saved.
I guess Twisted reactor can do the number three job. But how?
Thanks so much for any help and suggestions.
upd1:
A simple code example. I donβt know how the reactor works with processes, so I gave it imaginary functions:
datum = 'abcdefg' def dataServer(data): for char in data: yield chara def dataWorker(chara): return ord(chara) r = reactor() NUMBER_OF_PROCESSES_AV = 4 serv = dataserver(datum) id = 0 result = array(len(datum)) while r.working(): if NUMBER_OF_PROCESSES_AV > 0: r.addTask(dataWorker(serv.next(), id) NUMBER_OF_PROCESSES_AV -= 1 id += 1 for pr, id in r.finishedProcesses(): result[id] = pr
Rince source share