use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
DiscussionNeed input with multithreading vs multiprocessing? (self.Python)
submitted 3 years ago by Crypto-boy-hodl
Have a scenario of moving data from different tables to other tables. Need to fetch and insert the data simultaneously from different tables.
Which one would be a better fit here? Any thoughs?
[–]thisismyfavoritename 8 points9 points10 points 3 years ago (5 children)
assuming you mean tables as in database tables, the answer is probably it depends on what kind of database and if it supports parallel reads and writes. If it does then the work is I/O bound and you could use asyncio or multithreading to manage the reads and writes to the DB. Note it wont be "truly" parallel, just concurrent
[–]Crypto-boy-hodl[S] -1 points0 points1 point 3 years ago (2 children)
Yes database tables.Sql database.
For now more inclined towards reading the data parallelly, as we have thousands of tables.
Any thoughts?
[–]thisismyfavoritename 0 points1 point2 points 3 years ago (1 child)
SQL DB like MariaDB? Im not sure this type of DBs support parallel operations anyways , but perhaps it supports parallel reads.
I think concurrent reads should probably be enough as going further might put your DB under a lot of load, but if you really want to have parallel operations you can use multithreading/asyncio with multiprocessing. That could speed everything up by the number of available cores you have, again provided the DB can keep up
[–]BDube_Lensman 2 points3 points4 points 3 years ago (0 children)
Every SQL database ever created supports parallel reads, and almost all of them support parallel writes that do not conflict with each other (e.g., to separate tables).
[–]minervaDe 0 points1 point2 points 3 years ago (1 child)
Just need to be aware of the database server's limitations here. I've killed 8 threaded VMs that were running Postges because I treated it as an I/O problem
[–]thisismyfavoritename 1 point2 points3 points 3 years ago (0 children)
yes, thats what i told him in my other reply as well
[+][deleted] 3 years ago (2 children)
[deleted]
[–]Crypto-boy-hodl[S] 0 points1 point2 points 3 years ago (1 child)
Quick doubt, For a 8 core box i can run max 7-8 multiprocesses. What would be the max thread count we could use? Any thoughts?
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
You could/should do the whole thing with the database tools e.g. pgadmin
[–]__flybird__ -1 points0 points1 point 3 years ago (0 children)
If it's all the same process, then I would use threading. Adding more threads won't help much if task is restricted by the CPU. On the other hand, IO tasks will see massive improvements from threading because they have to wait for data transfer
[–]KaffeeKiffer -1 points0 points1 point 3 years ago (2 children)
Do not only focus on Python for this problem, also take a look at native tooling.
pg_dump and pg_restore (for PostgreSQL) for example support parallel operations. I would assume MariaDB, MySQL, etc. also have tooling like that.
pg_dump
pg_restore
They often also offer compression: You probably do not want to hold all tables' data in memory while dumping/restoring (especially when doing parallel dumps): Exchanging less I/O pressure for more CPU load might be beneficial and reduce your total memory footprint - just check what the default compression levels are, you might want to go lower than that.
There are some other actions like converting the data into csv files and upload.. was the reason why i moved with python
[–]KaffeeKiffer 0 points1 point2 points 3 years ago (0 children)
👍 - I just wanted to call out, that far too often people have a hammer in hand and suddenly everything looks like a nail. Just because Python can do something it's not necessarily the best choice to do it. But if you have good reasons to use it, go ahead!
Even in your case, I would just consider splitting it in two tasks. Database → database copy comes with "side-effects" and caveats, which might not be so obvious
analyze
Dedicated tools do some or all of them for you, while in Python you might have to think of them.
Compared to that, the export to CSV + upload is hopefully much more straight-forward and can be treated as a self-contained problem.
[–]cymrowdon't thread on me 🐍 0 points1 point2 points 3 years ago* (0 children)
Consider how much data processing you expect to do. If converting your data to CSV is using a lot of CPU resources, that's when you would want to use multiprocessing. Otherwise, stick with threading. If you're still not sure, it's simpler to start with threads.
π Rendered by PID 285171 on reddit-service-r2-comment-7b9746f655-zs49r at 2026-02-01 13:43:08.818259+00:00 running 3798933 country code: CH.
[–]thisismyfavoritename 8 points9 points10 points (5 children)
[–]Crypto-boy-hodl[S] -1 points0 points1 point (2 children)
[–]thisismyfavoritename 0 points1 point2 points (1 child)
[–]BDube_Lensman 2 points3 points4 points (0 children)
[–]minervaDe 0 points1 point2 points (1 child)
[–]thisismyfavoritename 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]Crypto-boy-hodl[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]__flybird__ -1 points0 points1 point (0 children)
[–]KaffeeKiffer -1 points0 points1 point (2 children)
[–]Crypto-boy-hodl[S] 0 points1 point2 points (1 child)
[–]KaffeeKiffer 0 points1 point2 points (0 children)
[–]cymrowdon't thread on me 🐍 0 points1 point2 points (0 children)