logo
down
shadow

Python subprocess doesn't work without sleep


Python subprocess doesn't work without sleep

By : user3100396
Date : January 12 2021, 07:00 PM
fixed the issue. Will look into that further As soon as the last thread is started, your main() returns. That in turn will exit your Python program. That stops all your threads.
From the documentation on daemon threads:
code :
for path in pathes:
    try:
        print(path)
        newThread = threading.Thread(target=executeFile, args=(path,))
        newThread.start()
    except:
        print("cant start thread for", path)
import os
import subprocess
import time


def manageprocs(proclist):
    """Check a list of subprocesses for processes that have
       ended and remove them from the list.

    :param proclist: list of Popen objects
    """
    for pr in proclist:
        if pr.poll() is not None:
            proclist.remove(pr)
    # since manageprocs is called from a loop,
    # keep CPU usage down.
    time.sleep(0.5)


def main():

    # Read config file
    try:
        with open('./config.ini', 'r') as f:
            pathes = [path.strip() for path in f.readlines()]
    except FileNotFoundError:
        print("cant find config file")
        exit(1)

    # List of subprocesses
    procs = []
    # Do not launch more processes concurrently than your
    # CPU has cores.  That will only lead to the processes
    # fighting over CPU resources.
    maxprocs = os.cpu_count()
    # Launch all subprocesses.
    for path in pathes:
        while len(procs) == maxprocs:
            manageprocs(procs)
        procs.append(subprocess.Popen(path, shell=True))
    # Wait for all subprocesses to finish.
    while len(procs) > 0:
        manageprocs(procs)


if __name__ == '__main__':
    main()


Share : facebook icon twitter icon
python stream subprocess stdout and stderr zip doesnt work

python stream subprocess stdout and stderr zip doesnt work


By : zigmoi
Date : March 29 2020, 07:55 AM
To fix the issue you can do zip stops when one of the iterators is finished.
In each of the examples you gave, one stream(stdout/stderr) is empty. So zip will produce nothing.
My firewall icon doesnt work.....I have tried setting up the JAVA path but for some reason, it doesnt work

My firewall icon doesnt work.....I have tried setting up the JAVA path but for some reason, it doesnt work


By : rooeye
Date : March 29 2020, 07:55 AM
this one helps. Your PATH may contain spaces. First, properly quote it. And, you might have another jdk earlier in the PATH (so set it first). Something like
code :
set "PATH=c:\amir\jdk1.7.0_45\bin;%PATH%"
cd c:\myutilities\auth
java -jar auth.jar
@echo off
setlocal
set "PATH=c:\amir\jdk1.7.0_45\bin;%PATH%"
java -jar c:\myutilities\auth\auth.jar
endlocal
how can i use sleep function in python subprocess

how can i use sleep function in python subprocess


By : Ruchika Sachdeva
Date : March 29 2020, 07:55 AM
Any of those help Standard output is buffered. You should flush the buffer after each print:
code :
from time import sleep
import sys
if __name__ == "__main__":
    for i in range(10):
        print(i)
        sys.stdout.flush()
        sleep(1)
Why are Python operations 30× slower after calling time.sleep or subprocess.Popen?

Why are Python operations 30× slower after calling time.sleep or subprocess.Popen?


By : Pras
Date : March 29 2020, 07:55 AM
may help you . my guess would be that this is due to the Python code being evicted from various caches in the CPU/memory system
the perflib package can be used to extract more detailed CPU level stats about the state of the cache — i.e. the number of hits/misses.
code :
from subprocess import Popen, DEVNULL
from perflib import PerfCounter
import numpy as np

arr = []
p = PerfCounter('LIBPERF_COUNT_HW_CACHE_MISSES')                                                        

for i in range(100):
  ti = []
  p.reset()
  p.start()
  ti.extend(p.getval() for _ in range(7))
  Popen(['echo'], stdout=DEVNULL)
  ti.extend(p.getval() for _ in range(7))
  p.stop()
  arr.append(ti)


np.diff(np.array(arr), axis=1).mean(axis=0).astype(int).tolist()                                                
 2605,  2185,  2127,  2099,  2407,  2120,
5481210,
16499, 10694, 10398, 10301, 10206, 10166
asyncio.sleep doesnt put my loop to sleep?

asyncio.sleep doesnt put my loop to sleep?


By : Ankit Khandelwal
Date : March 29 2020, 07:55 AM
wish helps you I needed a task that would be done every day and since for this specific bot I'm using discord.py I'm on 3.6 and and have a lot of things on_message and on_reaction that I don't want to stop, so I'm not using time.sleep(). Someone suggested I use asyncio.sleep with a loop, because I really didnt want to use threading. I tried playing around with it to see how it works and made a simple little loop. The problem is that even though I'm trying to put it to sleep it still fires out prints (pic provided) !http://prntscr.com/n8ar0u , You need to await the sleep : )
code :
await asyncio.sleep(..)
Related Posts Related Posts :
  • Tuning the hyperparameter with gridsearch results in overfitting
  • some coordinates that I extracted from geocoder in Python are not saving in the variable I created
  • 7C in cs circles- python Im not sure what is wrong with this yet
  • How to fix 'AttributeError: 'list' object has no attribute 'shape'' error in python with Tensorflow / Keras when loading
  • python - thread`s target is a method of an object
  • Retrieve Variable From Class
  • What is the reason for matplotlib for printing labels multiple times?
  • Why would people use ThreadPoolExecutor instead of direct function call?
  • When clear_widgets is called, it doesnt remove screens in ScreenManager
  • Python can't import function
  • Pieces doesn't stack after one loop on my connect4
  • How to change font size of all .docx document with python-docx
  • How to store a word with # in .cfg file
  • How to append dictionaries to a dictionary?
  • How can I scrape text within paragraph tag with some other tags then within the paragraph text?
  • Custom entity ruler with SpaCy did not return a match
  • Logging with two handlers - one to file and one to stderr
  • How to do pivot_table in dask with aggfunc 'min'?
  • This for loop displays only the last entry of the student record
  • How to split a string by a specific pattern in number of characters?
  • Python 3: how to scrape research results from a website using CSFR?
  • Setting the scoring parameter of RandomizedSeachCV to r2
  • How to send alert or message from view.py to template?
  • How to add qml ScatterSeries to existing qml defined ChartView?
  • Django + tox: Apps aren't loaded yet
  • My css and images arent showing in django
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org