logo
down
shadow

a thread python with 'while' got another thread never start


a thread python with 'while' got another thread never start

Content Index :

a thread python with 'while' got another thread never start
Tag : python , By : al.
Date : January 11 2021, 03:34 PM

hop of those help? this should work. The reason why yours doesnt is because you are passing the function, a1() into the target. target takes in a callable object so by passing in the entire function inside, what you are actually doing is passing in the return value, which is None in this case. showprogress() will then execute after a() which will also pass in None into the parameter.
If you would like to pass arguments into your function, what you can do is
import threading, time

a = 0
def a1():
    print('adding')
    global a
    while a < 1000:
        a+=1
        print('a from a1', a)
        time.sleep(1)


def showprogress():
    global a
    print(a)
    time.sleep(3)
    print(a)
    time.sleep(3)
    print(a)

t1 = threading.Thread(target=a1)
t2 = threading.Thread(target=showprogress)
t1.start()
t2.start()
t1.join()
t2.join()

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Start a new thread in Python with a callback method in Main Thread for PyQT application


Tag : python , By : user96271
Date : March 29 2020, 07:55 AM
I wish this help you You need to use QThread and signal and slots. QThread inherits from QObject, which allows to emit signals.
Upon the completion of the task, the QThread will emit a finished() signal
class CustomThread(QtCore.QThread):
    def __init__(self, target, slotOnFinished=None):
        super(CustomThread, self).__init__()
        self.target = target
        if slotOnFinished:
            self.finished.connect(slotOnFinished)

    def run(self, *args, **kwargs):
        self.target(*args, **kwargs)
class MyCustomWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        super(MyCustomWidget, self).__init__(parent)
        layout = QtGui.QVBoxLayout(self)
        button = QtGui.QPushButton("Start", self)
        layout.addWidget(button)    
        button.clicked.connect(self.onStart)
        self.actionthread = CustomThread(target=self.longAction, self.onFinished)

    def onFinished(self):
        # Do Something

    def longAction(self):
        time.sleep(3)

    def onStart(self): 
        self.actionthread.start()

Python threading.thread.start() doesn't return control to main thread


Tag : python , By : nickthecook
Date : March 29 2020, 07:55 AM
seems to work fine
Thread.start() never returns! Could this have something to do with the C implementation of the math library?
print(message) # works

Python - how to do not start thread on build thread step


Tag : python , By : mediafarm
Date : March 29 2020, 07:55 AM
it should still fix some issue The problem is that you are invoking (calling) the function instead of passing it to the Thread class, so instead of
t = threading.Thread(target=geter(token), args=(token,))
t = threading.Thread(target=geter, args=(token,))

Python 3.6 - How to start a thread from within a daemon thread and have sub-thread exit once the function it is running


Tag : python , By : meodudang
Date : March 29 2020, 07:55 AM
I wish this help you After much searching and investigation I was able to find a solution to the issue by using information in this stackoverflow answer on threading
Basically I found that I was able to start a new thread from within a thread using the code below:
t = threading.Thread(target=target_function,args=(args))
t.daemon = True
t.start()
import threading

threads = []


def func1():
    // runs in its own thread and receives messages from a message queue

def func2():
    // runs in its own thread and sends messages in a loop to a message queue

def func3():
    // runs in its own thread and receives messages from a message queue, does some
    // processing, assigns value to variable_from_func3

    t = threading.Thread(target=func4,args=(variable_from_func3))
    t.daemon = True
    t.start()

    // Code above starts func4 in its own thread passing variable_from_func3 as an arg


def func4(variable_from func3):
    // performs actions on variable passed from func3  
    // This now runs in its own thread which dies once complete

def manager():

# Thread t1 
t1 = threading.Thread(target=func1)
t1.daemon = True
threads.append(t1)

# Thread t2
t2 = threading.Thread(target=func2)
t2.daemon = True
threads.append(t2)
t2.start()

# Thread t3 
t3 = threading.Thread(target=func3)
t3.daemon = True
threads.append(t3)
t3.start()

t1.start()
for t in threads: 
t.join()

manager()

Python: I start a new thread, and my program pauses until the thread is finished


Tag : python , By : uxn
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , When I try to start a new thread, my entire program stops until the thread's function finishes. I am trying to make the thread start and continue while my program runs at the same time. , By doing
do_python("key = cpc.get_key()")
getKeyThread = threading.Thread(target=do_python, args=some_args, daemon=True).start()
Related Posts Related QUESTIONS :
  • 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
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com