-2

Python3.6 I have bunch of queries (2000+) in a single file. I can connect to the DB and execute one by one.

how can I run 5 threads and run 5 queries parallel in these threads, by reading from this file so that I can save time ? any sample code will be a great help...

Thanks, Kiran

kirantd
  • 47
  • 3
  • 1
    please, if you post some question in stackoverflow.com, add the source code of your try, also if it's not working. Thanks – alepuzio Mar 22 '18 at 21:54
  • Happy Coding. SO is about fixing _your_ Code - not implementing your ideas. Please go over [how to ask](https://stackoverflow.com/help/how-to-ask) and [on-topic](https://stackoverflow.com/help/on-topic) again and if you have questions provide your code as [mvce](https://stackoverflow.com/help/mcve). If you encounter errors, copy and paste the error message verbatim ( word for word) into your question. Avoid using screenshots unless you need to convey layout errors. We can NOT copy and paste your image into our IDEs to fix your code. – Patrick Artner Mar 22 '18 at 22:36

1 Answers1

0

how can I run 5 threads and run 5 queries parallel in these threads, by reading from this file so that I can save time ?

To be honest, I highly doubt that multithreading is a good solution for this because your file isn't that big - just read it sequentially with open().... Running this task concurrently wouldn't result in greater speed/performance. Also, before you try multithreading in python, have a look at GIL or/and at What is a global interpreter lock (GIL)?.

Community
  • 1
  • 1
Anthony
  • 421
  • 1
  • 5
  • 13