You need to join the child process when your finished with it. Here's a cleaner example of what your trying to achieve. Notice how all of the stuff related to the process is encapsulated out into one class? It makes dealing with threads and process much easier if you can interact with them through a clean interface.
Here's the main module
from asynctimer import AsyncTimer
import time
def run():
atimer = AsyncTimer()
atimer.start()
print 'initial count: ', atimer.get_seconds();
print 'Now we wait this process,'
print 'While the child process keeps counting'
time.sleep(3)
print '3 seconds later:', atimer.get_seconds();
atimer.stop()
if __name__ == '__main__':
run()
Here's the class that handles the child process.
from multiprocessing import Process, Value
class AsyncTimer():
def __init__(self):
self._proc = None
self._do_count = Value('b',True)
self._count = Value('i', 0)
def _count_seconds(self):
while self._do_count.value:
self._count.value += 1
def start(self):
self._proc = Process(target=self._count_seconds)
self._proc.start()
def stop(self):
self._do_count.value = False
self._proc.join()
def get_seconds(self):
return self._count.value