Python Forum
count certain task in task manager[solved]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count certain task in task manager[solved]
#1
hi, sorry for my bad English
I creating a downloader to download multiple files at once using python,
I will not write details, this is the part:
if not os.path.exists(SaveAs):
    time.sleep(1.0) # download size average is under 1 Mb
    Calling = 'python.exe', "DownloadSingle.py", URL, SaveAs
    subprocess.Popen(Calling)
now my problem is: that sometimes, the file is over 1Mb, and the subprocess keeps increasing,
   
I want to limit it by using a script like this(just an idea)

while taskmanager.count("Python") > 4:
     time.sleep(1.0)
how do I do this?
thank you, have a nice day
I just find the correct keyword: python get all running task manager
Reply
#2
Can use psutil for this.
Example.
import psutil

count = 0
PROCNAME = "python.exe"
for proc in psutil.process_iter():
        if proc.name() == PROCNAME:
            count += 1

print(count)
Output:
3
(Aug-29-2022, 04:29 PM)kucingkembar Wrote: I want to limit it by using a script like this(just an idea)
while taskmanager.count("Python") > 4:
    time.sleep(1.0) 
how do I do this?
Don't use time.sleep() when what to schedule at task as certain interval,use eg schedule
Look at my post here,you can rewrite it a little to check that just a limited of prosses is spawned.
kucingkembar likes this post
Reply
#3
(Aug-29-2022, 04:58 PM)snippsat Wrote: Can use psutil for this.
Example.
import psutil

count = 0
PROCNAME = "python.exe"
for proc in psutil.process_iter():
        if proc.name() == PROCNAME:
            count += 1

print(count)
Output:
3
(Aug-29-2022, 04:29 PM)kucingkembar Wrote: I want to limit it by using a script like this(just an idea)
while taskmanager.count("Python") > 4:
    time.sleep(1.0) 
how do I do this?
Don't use time.sleep() when what to schedule at task as certain interval,use eg schedule
Look at my post here,you can rewrite it a little to check that just a limited of prosses is spawned.
thank you for the reply, I used that medhod,
I use time.sleep() because I download using for loop, if file do not exist : take a breath 1second ,then download
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Running Python script through Task Scheduler? Winfried 8 521 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Background task Mctweed 4 452 Feb-13-2024, 11:50 PM
Last Post: Mctweed
  How can I multithread to optimize a groupby task: davisc4468 0 714 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  [SOLVED] Why is this asyncio task blocking? SecureCoop 1 783 Jun-06-2023, 02:43 PM
Last Post: SecureCoop
  Start print a text after open an async task via button Nietzsche 0 715 May-15-2023, 06:52 AM
Last Post: Nietzsche
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 2,513 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  Row Count and coloumn count Yegor123 4 1,337 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  add interrupt for next task kucingkembar 0 779 Oct-07-2022, 12:15 PM
Last Post: kucingkembar
  How to add another task? Makada 2 1,501 Nov-03-2021, 05:38 PM
Last Post: Makada
  Need some coding guidance for a task peny 5 2,196 Sep-27-2021, 02:02 PM
Last Post: peny

Forum Jump:

User Panel Messages

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