-2

Actually I do not mean a shell background process like using a "&". I run into a situation that I want to create another process for preparing data (class_data) and a process for computing (class_process). As the (class_data) can generate while (class_process) is processing. I wanna to subclass a thread class just like in java. I just want to the (class_data) to run asynchronous. A sketch maybe as follows:

class_data.init_generate()
for i in range(100):
    class_data.generate()
    class_process.process(class_data.data)
    class_data.collect()

The generate method may generate a batch data and the collect just wait for the data to be generated and renew the class_data.data to the newly generated.

I am not sure whether I make myself clear, and thanks in advance!

kuantkid
  • 569
  • 1
  • 4
  • 5
  • This a duplicate of http://stackoverflow.com/questions/9873713/parallel-for-in-python – Bull Apr 26 '13 at 10:19
  • I do not think this is a duplicate. Actually I wanna know whether I can just subclass the Process class as what I can do in java. – kuantkid Apr 26 '13 at 12:28

1 Answers1

2

Python has a multiprocessing module which offers synchronization, sharing data between processes, etc.

E.Z.
  • 6,393
  • 11
  • 42
  • 69
  • Could you give more specific details on it? I tried with apply_async but it could not handle when generate() is a instancemethod rather than a function. – kuantkid Apr 26 '13 at 11:41
  • I don't think you can use it with instance methods in a straight forward way. See the discussion here: http://stackoverflow.com/q/1816958/15931 – E.Z. Apr 26 '13 at 11:50