On 24/09/14 00:47, Matthew Solomonson wrote:
Hi all,
I'd like to write a python script that can execute coot functions from a new
thread. I noticed a function run_python_thread() defined in coot_gui.py that
might be useful for this. For example:
# script for adding a water every 2 seconds
import time
def addWater():
while True:
time.sleep(2)
print "water placed"
place_typed_atom_at_pointer('Water') # causes segmentation
error
run_python_thread(addWater, ())
This new thread correctly prints "water placed" to the terminal every 2
seconds. However, Coot crashes with a segmentation error when
place_typed_atom_at_pointer('Water') is executed. This error only occurs when Coot
functions are executed from the new thread. Any suggestions? I don't want the main thread
to be interrupted (the gui shouldn't freeze up). I've tried using Coot-0.7.1 stable and
Coot-0.8-pre-5335, both for Mac. Thanks for any help, I'm a bit new to scripting.
Hi,
Like all OpenGL and GTK+ programs, only the main thread can manipulate
the graphics/gui.
You can use python threads (or so I imagine, I haven't tried it myself)
but you need to use a semaphore system, callback function and timeout
function. I found that it was not straightforward at all when doing
something analogous with guile. Many of the non-gui functions are
thread-safe (but not documented to be so).
Regards,
Paul.