I am writing a python script that will upload a file to a remote FTP server when the enter key is pressed on the keyboard.
Since the enter key can be pressed randomly, multiple threads/processes could spawn concurrently.
Now should I use threading or multiprocessing to execute the upload? Which is better and why?
So for real parallel work you would need multiprocessing, since threads only gives an advantage in a few cases (like IO).
As already pointed out, for your IO work threads should be fine, although you should look into multiprocessing, since from my experience it isn't hard to implement either.
Also it's way easier to get a return value from multiprocessing than from threads
If you want to know why threads is slower for most use cases you should read this: https://jeffknupp.com/blog/2012/03/31/pythons-hardest-problem/
Edit: Also keep in mind that for simple tasks threads and multiprocessing actually increase the runtime, since the overhead from allocating threads/processes and higher memory usage from multiprocessing due to no shared memory are quite significant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With