If I terminate the process, the thread would also stop?
<p>I've following code :</p>

<pre><code>#!/usr/bin/python3
import os
import subprocess
import time
import threading


class StartJar(threading.Thread):
    def run(self):
        os.system("java -jar &lt;nazwa_appki&gt;.jar")

jarFileRun = StartJar        
current_location = subprocess.getoutput("pwd")

while True:
    x = subprocess.getstatusoutput("git checkout master &amp;&amp; git reset --hard &amp;&amp; git fetch &amp;&amp; git pull")
    if x[0] is 0:
        os.system("git checkout master &amp;&amp; git reset --hard &amp;&amp; git fetch &amp;&amp; git pull")
        os.system("mvn clean package ~/your/path")

        try:
            process_pid = subprocess.check_output(['pgrep', '-f', 'tu_podaj_nazwe_procesu']).decode()
        except subprocess.CalledProcessError as e:
            print("pgrep failed because ({}):".format(e.returncode), e.output.decode())
        else:
            try:
                os.kill(int(process_pid), 9)
                print('Process with ' + process_pid + ' PID was killed.')
            except ProcessLookupError as e:
                print("Process were old...")
            except ValueError as e:
                print("There is no such process!")

        os.system("cp ~/your/path" + ' ' + current_location)
        jarFileRun.start()
    else:
        print('No changes was made...')

time.sleep(1800)
</code></pre>

<p>And I wonder if I kill process that my thread runs, it would close as well ? If no how do i terminate the thread to be able to run it once more with new changes that had came out for the file I want to execute ?
I tried to find out in google something that stops thread but it didn't work for me when I added it to the first line of while statement.</p>

<p>No it will not terminate because the value <code>daemon</code> is by default False and it means that the thread doesn't stop when the main process finishes, it's totally independent. However, if you set the thread's daemon value to <code>True</code> it will run as long as the main process runs too.</p>

<p>In order to do so you can delete your <code>StartJar</code> class and define <code>jarFileRun</code>
like this:</p>

<pre><code>jarFileRun = threading.Thread(target=os.system, args=("java -jar &lt;nazwa_appki&gt;.jar",), daemon=True)
</code></pre>

<p>Or make an init definition inside the class for <code>daemon</code></p>

python multithreading python-3.x python-3.4 python-multithreading