schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.2k stars 281 forks source link

PyMOL is not responsive when performing task in background #248

Open kexul opened 2 years ago

kexul commented 2 years ago

Hi, I'd like to update my plugin when a new object is loaded in PyMOL, a watch process is created for this task:

def find_proteins():
    """
    Find all proteins in pymol
    Returns:

    """
    proteins = []
    for object_name in cmd.get_names_of_type('object:molecule'):
        if cmd.count_atoms(f'model {object_name} and {prot_and_dna_sele}') > 0:
            proteins.append(object_name)
    return proteins

def watch(self):
    while True:
        proteins = find_proteins()
        if proteins != self.proteins:
            self.update()
        self.proteins = proteins
        time.sleep(0.3)

thread = Thread(target=watch, daemon=True)
thread.start()

When the watch process is running in background, my PyMOL window is not responsive, I have to click many times to get the button working. Do you have any suggestions? Thanks!

Screenshot: responsive