Python scheduler threading vs 多個console 問題

用python scheduler 寫左個backup shcedule (按時run batch 或者vbs backup file or folder),發覺佢係一個batch 跑完,再跑另一個batch。

其實python 有一個threading 功能,不過要寫多好多行code,自己又吾係好明。自己用左個另類方法,每個batch file 都用一個新console 去跑。

其實咁樣開新console run batch同multithreading 是否等價?  效能是否相同?

Python's threads and multiple consoles. First, we need to clarify these two concepts.

Thread: A thread is the smallest unit that the operating system can perform operation scheduling. It is included in the process and is the actual operating unit in the process. Using threads can perform multiple operations at the same time, making the program run more efficiently. In Python, threading operations can be performed through the threading module.

Multiple consoles: By "new console" you may mean running a program in a new command line interface (CLI) or in a new terminal window. Each console can run its own program, but no state or resources are shared between them unless explicitly shared.

As for your question, "Does opening a new console to run batches equal multi-threading?", the answer is "not exactly the same". Running a program in a new console means that you are running the program in a new process, not a new thread. The main difference between processes and threads is that processes have their own memory space and resources, while threads share the memory and resources of the parent process.

"Is the performance the same?" The answer to this question depends on your specific needs. If your program is primarily CPU-intensive (i.e., it relies primarily on the computing power of the CPU), you may have better performance using multithreading, since multiple threads can execute in parallel within the same process, sharing memory and resource. If your program is primarily I/O-bound (i.e., it mostly waits for I/O operations, such as reading and writing files or network communications), you may have better performance using multiple processes, since multiple processes can execute in parallel , without being restricted by GIL (Global Interpreter Lock).

If you just want to back up files or folders regularly, you probably don't need to use threads or multiple processes. You can use Python's schedule module to run your script periodically.

TOP

非常清楚明白,睇黎開新cmd 仲好d

TOP

回復 3 #bongbong3481

你可以詳細研究下queue module 及使用worker
queue 係一堆排隊要完成工作
worker 係可以同時執行工作嘅單位

via HKEPC Reader for Android

TOP

回覆 4# epcsub


    原來可以玩咁多野,得閑研究下先,thx

TOP