Python Forum
python Multithreading on single file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python Multithreading on single file
#2
You can not create a class like this.
If want want place funcrion in class look at @staticmethod.
Make no sense here so just remove the class.
Also to check that it works the time should be around 5-sec and not 10-sec.
# th.py
import threading
from time import sleep

def create_checksum(path):
    sleep(5)
    print("checksum Created")

def create_gzip(path):
    sleep(5)
    print("gzip_Created")

def main():
    path = "d:\\output\\abc.csv"
    # Call Checksum Function to generate Checksum no
    t1 = threading.Thread(target=create_checksum, args=(path,))
    t2 = threading.Thread(target=create_gzip, args=(path,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    # both threads completely executed
    print("Done!")

if __name__ == "__main__":
    main()
Output:
=== python th.py === checksum Created gzip_Created Done! Execution time: 5.228 s
Reply


Messages In This Thread
python Multithreading on single file - by mg24 - Nov-04-2022, 12:35 PM
RE: python Multithreading on single file - by snippsat - Nov-04-2022, 02:19 PM
RE: python Multithreading on single file - by mg24 - Nov-04-2022, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  multithreading xlwings error Equivocal 0 508 Jan-25-2025, 05:10 PM
Last Post: Equivocal
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 3,844 Dec-14-2022, 11:35 PM
Last Post: deanhystad
  python sql query single quote in a string mg24 1 2,338 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  Create multiple/single csv file for each sql records mg24 6 3,099 Sep-29-2022, 08:06 AM
Last Post: buran
  multithreading Hanyx 4 2,332 Jul-29-2022, 07:28 AM
Last Post: Larz60+
Question Problems with variables in multithreading Wombaz 2 2,193 Mar-08-2022, 03:32 PM
Last Post: Wombaz
  [SOLVED] Input parameter: Single file or glob? Winfried 0 2,133 Sep-10-2021, 11:54 AM
Last Post: Winfried
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 8,841 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Multithreading question amadeok 0 2,388 Oct-17-2020, 12:54 PM
Last Post: amadeok
  How do I write a single 8-bit byte to a file? MysticLord 2 4,260 Sep-03-2020, 12:27 PM
Last Post: MysticLord

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020