Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Python3 Multiprocessing

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


devyncjohnson at gmail

Aug 9, 2013, 12:30 PM

Post #1 of 5 (23 views)
Permalink
Python3 Multiprocessing

Aloha!

I need a command that will make threads created by
"multiprocessing.Process()" wait for each other to complete. For
instance, I want to do something like this:

job1 = multiprocessing.Process(CMD1())
job2 = multiprocessing.Process(CMD2())

jobs1.start(); jobs2.start()

PY_FUNC()

The command "PY_FUNC()" depends on the end result of the actions of
CMD1() and CMD2(). I need some kind of wait command for the two threads
that will not let the script continue until job1 and job2 are complete.
Is this possible in Python3?


Mahalo,

DevynCJohnson [at] Gmail
--
http://mail.python.org/mailman/listinfo/python-list


python at mrabarnett

Aug 9, 2013, 12:44 PM

Post #2 of 5 (22 views)
Permalink
Re: Python3 Multiprocessing [In reply to]

On 09/08/2013 20:30, Devyn Collier Johnson wrote:
> Aloha!
>
> I need a command that will make threads created by
> "multiprocessing.Process()" wait for each other to complete. For
> instance, I want to do something like this:
>
> job1 = multiprocessing.Process(CMD1())
> job2 = multiprocessing.Process(CMD2())
>
> jobs1.start(); jobs2.start()
>
> PY_FUNC()
>
> The command "PY_FUNC()" depends on the end result of the actions of
> CMD1() and CMD2(). I need some kind of wait command for the two threads
> that will not let the script continue until job1 and job2 are complete.
> Is this possible in Python3?
>
Possibly you mean .join:

jobs1.start()
jobs2.start()

jobs1.join()
jobs2.join()

--
http://mail.python.org/mailman/listinfo/python-list


devyncjohnson at gmail

Aug 9, 2013, 1:43 PM

Post #3 of 5 (22 views)
Permalink
Re: Python3 Multiprocessing [In reply to]

On 08/09/2013 03:44 PM, MRAB wrote:
> On 09/08/2013 20:30, Devyn Collier Johnson wrote:
>> Aloha!
>>
>> I need a command that will make threads created by
>> "multiprocessing.Process()" wait for each other to complete. For
>> instance, I want to do something like this:
>>
>> job1 = multiprocessing.Process(CMD1())
>> job2 = multiprocessing.Process(CMD2())
>>
>> jobs1.start(); jobs2.start()
>>
>> PY_FUNC()
>>
>> The command "PY_FUNC()" depends on the end result of the actions of
>> CMD1() and CMD2(). I need some kind of wait command for the two threads
>> that will not let the script continue until job1 and job2 are complete.
>> Is this possible in Python3?
>>
> Possibly you mean .join:
>
> jobs1.start()
> jobs2.start()
>
> jobs1.join()
> jobs2.join()
>

Thanks MRAB! That is easy. I always (incorrectly) thought the join()
command got two threads and made them one. I did not know it made the
script wait for the threads.

Mahalo,

DevynCJohnson [at] Gmail
--
http://mail.python.org/mailman/listinfo/python-list


ramit.prasad at jpmorgan

Aug 9, 2013, 1:46 PM

Post #4 of 5 (17 views)
Permalink
RE: Python3 Multiprocessing [In reply to]

Devyn Collier Johnson
> On 08/09/2013 03:44 PM, MRAB wrote:
> > On 09/08/2013 20:30, Devyn Collier Johnson wrote:
[snip]
> >>
> > jobs1.join()
> > jobs2.join()
> >
>
> Thanks MRAB! That is easy. I always (incorrectly) thought the join()
> command got two threads and made them one. I did not know it made the
> script wait for the threads.
>

It does join two threads, just not the threads you think! It "joins"
a child thread with the parent thread and not two children thread.

> Mahalo,
>
> DevynCJohnson [at] Gmail
> --


~Ramit




This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list


random832 at fastmail

Aug 9, 2013, 1:54 PM

Post #5 of 5 (22 views)
Permalink
Re: Python3 Multiprocessing [In reply to]

On Fri, Aug 9, 2013, at 16:43, Devyn Collier Johnson wrote:
> Thanks MRAB! That is easy. I always (incorrectly) thought the join()
> command got two threads and made them one. I did not know it made the
> script wait for the threads.

What you're missing is the fact that the main thread [.i.e. the one
running "the script", and that waits for the thread you call the method
on] is, well, a thread. So, you start with two threads [the main thread
and the jobs1 thread, for example], and end up with one [the main
thread]. This is why it's called join.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.