import mfhclient
import os
import Queue
import sys
import threading
import trigger
import update


def main():
    q = Queue.Queue()
    updateq = Queue.Queue()
    mfhclient_thread = threading.Thread(
        args=(q,),
        name="mfhclient_thread",
        target=mfhclient.main,
        )
    mfhclient_thread.start()
    trigger_thread = threading.Thread(
        args=(updateq,),
        name="trigger_thread",
        target=trigger.trigger,
        )
    trigger_thread.start()
    count = 0
    while True:
        if updateq.empty() and updateq.get() == "update":
            q.put("quit")
        if not mfhclient_thread.is_alive():
            updater_thread = threading.Thread(
                args=("origin", "master"),
                name="updater_thread",
                target=update.pull,
                )
            updater_thread.start()
            updater_thread.join()
            sys.stdout.flush()
            os.execl(sys.executable, sys.executable, *sys.argv)
        count += 1

if __name__ == '__main__':
    main()

import os
import sys
import time
from multiprocessing import Process, Event

import mfhclient
import update
from arguments import parse


def main():
    q = Event()
    mfhclient_process = Process(
        args=(args, q,),
        name="mfhclient_process",
        target=mfhclient.main,
        )
    mfhclient_process.start()
    trigger_process = Process(
        args=(q,),
        name="trigger_process",
        target=update.trigger,
        )
    trigger_process.start()
    trigger_process.join()
    while mfhclient_process.is_alive():
        time.sleep(5)
    else:
        update.pull("origin", "master")
        sys.stdout.flush()
        os.execl(sys.executable, sys.executable, *sys.argv)

if __name__ == '__main__':
    # Parse arguments
    args = parse()
    main()

Switch from multithreading to multiprocessing
Switch from multithreading to multiprocessing

It is easier to work with processes in terms of the current task.
The task was to make the client and updater work at the same time.
Threads have a lot of limitations and are harder to get right, so I
switched to processes.
The code went pretty much straightforward.
Not on the first try, though.
