![]() |
| ||||||||||||||||||
![]() |
| ||||||||||||||||||
|
While a Python plugin is running, you can continue using YASARA normally. There are in fact two threads working in parallel: YASARA and the plugin. When a plugin runs a YASARA command,
this command is passed from the plugin to YASARA and executed as soon as possible.
It is NOT guaranteed that YASARA has finished a command when the function call in the plugin returns.
This can lead to potential problems if there is a data dependency between YASARA and the plugin,
usually involving files on the hard drive accessed by both threads. In such cases,
it is therefore essential that the plugin waits for YASARA to finish execution. This is done by calling the
'Finish' function: yasara.Finish()
Starting with YASARA 4.8.5, the Finish() function is called automatically by most critical YASARA commands that write to the hard drive and is thus not needed anymore.
The only exception is the LogAs command:
# Log the output of the next command
yasara.LogAs("MyLog")
# List all lysine residues
yasara.ListRes("Lys")
# Finish writing the log file
yasara.Finish()
# Read the log file in Python
log=open("MyLog").readlines()
This is normally not a problem, unless the file is a temporary one,
and the plugin decides to delete it. In this case, the plugin must wait for YASARA to read the file before deleting it:
# DOWNLOAD A PDB FILE FROM THE WEB pdb=urllib.urlopen(url).readlines() # SAVE IT TEMPORARILY open(pdbfilename,"w").writelines(pdb) # READ IT IN YASARA yasara.LoadPDB(pdbfilename) # FINISH READING yasara.Finish() # DELETE THE TEMPORARY FILE os.path.remove(pdbfilename) Instead of waiting for YASARA, one can also let YASARA delete the file,
which avoids synchronization issues: # READ IT IN YASARA yasara.LoadPDB(pdbfilename) # AND DELETE yasara.DelFile(pdbfilename)
| ||||||||||||||||||