[Tutor] could someone please explain multiprocessing

nathan tech nathan-tech at hotmail.com
Fri Jul 3 23:01:56 EDT 2020


Hi Alan and Mats,


First up I wanted to address the questions raised by Alan regarding my 
mention of sockets.

What I meant by this was:

1. There is one centralised program file, lets call this program.py.

2. Upon launch, program.py attempts to connect to localhost:6868 (just 
an example). If this works, it sends a message then exits.

3. If it fails, the program then listens on the said port, and waits (or 
allows the user to do other things such as play other music). When it 
receives the message it then processes it.


My basic aim was to try and find a way around the age old problem of:


If program is already running, don't run it again instead just tell it 
some info.


In terms of WMP, what I was referring to there was basically what I 
explained above, it has the ability to launch the media player, play a 
song and if you play another file (by clicking on it), it does not open 
two instances of WMP instead it just adds that to the one being played 
and plays it after.


To be honest I actually do have the entire concept working with a 
sockets backend, kind of a client/server situation but my main problem 
is that windows throws up a security alert (most likely the firewall).


I mean I guess I could force something in the installer, but really, if 
a simple media player requires you modify security settings, am I the 
only one who scratches his head and thinks "no thanks."


That's why I then turned to multiprocessing it seems a safer alternative.


I'll definitely check out your tutorial Alan, so thanks very much for that.


Finally i wanted to address Mats response (very appreciated). I have 
studied a couple of examples, documented and otherwise and the main 
question I kept coming across was:


"But, what if I want it to track down a different process to pass the 
information too?"


That is why I came to the list.


Hope this helps and I'm sorry for being so vague. (It's honestly not 
intentional!)

Nathan

On 03/07/2020 20:47, Mats Wichmann wrote:
> On 7/2/20 5:20 PM, nathan tech wrote:
>> Hi tutor List,
>>
>>
>> I hope everyone is keeping safe and doing well.
>>
>> I was wondering if someone was able to explain the multiprocessing
>> module to me.
>>
>> I'm trying to get it to where my program would be able to do something
>> like:
>>
>> Hi parent, are you running?
>>
>> Yes I am.
>>
>> Great, here is a file for you.
>>
>> Thanks child, you can close now and not launch a second instance.
>>
>> okay, goodnight!
>>
>>
>> So far the way I've done this is through the socket module by having the
>> first program listen on localhost, but this on some systems raises a
>> windows security error. This obviously makes it rather suspicious!
>
> Multiprocessing is easy, until it isn't.  Which usually happens fairly fast.
>
> "easy": kick off a new process to do a bit of self-contained work.
> "harder": send short messages between processes
> "also harder": coordinate between processes (locks, etc.)
> "still harder": send data between processes
>
> the documentation for the Python multiprocess module talks about all of
> these and more.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=02%7C01%7C%7Ccc71ca19c49e44c0468a08d81f8a1275%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637294025154600280&sdata=Yrhztil5rd7r3DM%2BPIR%2FWTi55nqfsrpiO6GfKPsuvls%3D&reserved=0


More information about the Tutor mailing list