1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- I think I'll spawn a process with multiprocessing.Process,
- then make a timer to periodically check if it has finished.
- When it does, reactivate the run button and stop the progressbar / spinner.
- https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.close
- Example usage of some of the methods of Process:
- >>> import multiprocessing, time, signal
- >>> p = multiprocessing.Process(target=time.sleep, args=(1000,))
- >>> print(p, p.is_alive())
- <Process ... initial> False
- >>> p.start()
- >>> print(p, p.is_alive())
- <Process ... started> True
- >>> p.terminate()
- >>> time.sleep(0.1)
- >>> print(p, p.is_alive())
- <Process ... stopped exitcode=-SIGTERM> False
- >>> p.exitcode == -signal.SIGTERM
- True
- #from my hello-world project:
- window = builder.get_object("myWindow")
- window.connect("destroy", Handlers.myDestroy)
- window.connect("destroy", Gtk.main_quit)
-
- #This is used to stop the music from playing if the user closes the window during playback.
- def myDestroy(self):
- print("Exit window button pressed!")
- global exitProcess
- if exitProcess is not None:
- print("Killing this process: " + str(exitProcess.pid))
- kill(exitProcess.pid, signal.SIGKILL)
- This is not usefull to me:
- https://stackoverflow.com/questions/19033818/how-to-call-a-function-on-a-running-python-thread
- from multiprocessing import dummy as multithreading
- class SomeClass(object):
- def doSomething(self):
- pass
- def doSomethingElse(self):
- pass
- someClass = SomeClass()
- pool = multithreading.Pool(1)
- pool.apply(someClass.doSomething)
- pool.apply(someClass.doSomethingElse)
- pool.apply(someClass.doSomething)
- pool.close()
- pool.join()
|