Ignore:
Timestamp:
May 20, 2014, 9:14:56 AM (11 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
74459a
Parents:
975b83
git-author:
Frederik Heber <heber@…> (08/26/13 22:56:36)
git-committer:
Frederik Heber <heber@…> (05/20/14 09:14:56)
Message:

ActionQueue now contains a run thread.

  • otherwise the progress bar of the QtMainWindow cannot be seen as waitForResults() takes up all of the executing thread.
  • added mutex for operations modifying the queue.
  • added ActionQueue::run() and ::stop(), used by friend stopQueue().
  • insertAction() now makes use of a tempqueue that is added to true queue during run() instead of calling the actions directly.
  • new stopQueue() in cleanUp.hpp is used by module_exit in pyMoleCuilder and in main() before saveAll().
  • cleanup: printTiming() requires now list of action tokens and added new stopAndPurgeQueue() to place waiting for Actions to end into extra function.
  • added ActionQueue::wait() which allows for synchronization in python scripts, is ignored in session python scripts. Otherwise we wait for ActionQueue's queue to empty during execution of load-session which hangs.
  • DOCU: added note to python documentation.
  • added waitQueue() also to purgeStaticInstances().
  • static UIFactory::isFactoryPresent() added that allows checking whether we have a UI or are executed within a python script (i.e. pyMoleCuilder).
  • DOCU: Extended docu on threads and who this affects python scripts.
  • TESTFIX: changed regression tests on storing python sessions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/documentation/userinterfaces/python.dox

    r975b83 r415ddd  
    2020 *  script.
    2121 *
    22  *  This is done in \b src/Actions/pyMoleCuilder.cpp.
     22 *  This is done in \b src/Python/PythonScripting.cpp.
    2323 *
    2424 *  There again some preprocessor magic is happening. One the one hand we
     
    4343 *  mol.SelectAtomById("0")
    4444 *  mol.AtomRemove()
     45 *  mol.wait()
     46 *  mol.getSelectedMolarMass()
     47 *  mol.wait()
    4548 *  \endcode
    4649 *  which loads a file \b test.xyz into the (internal) World, selects the first
    47  *  atom and removes it.
     50 *  atom and removes it. Notice \b mol.wait() at the end. This might be necessary
     51 *  as actions are executed in a different thread than the python script itself.
     52 *  Hence, if you require values from molecuilder you have to make sure that
     53 *  all your actions have been processed by this second thread. That's what
     54 *  wait() is good for. It waits until action queue thread is idle. Then you
     55 *  can be sure that molecuilder has removed all atoms, performed all selections
     56 *  and any value you retrieve is up-to-date.
     57 *
     58 *  Note that there are two \b wait()s present in the example. As the Actions
     59 *  are executed in another thread and the above commands just tell the MoleCuilder
     60 *  library (the ActionQueue to be precise) to enqueue the requested action,
     61 *  we have to wait (in the main thread) until the actions actually have been
     62 *  executed before we continue (i.e. when we need the new state where the
     63 *  atoms have been removed) and before we \b terminate!
    4864 *
    4965 *  \section userinterfaces-python-running Running a test script
     
    7288 *  \code
    7389 *  pyMoleCuilder.WorldInput("test.xyz")
     90 *  pyMoleCuilder.wait()
    7491 *  \endcode
    7592 *
     
    7895 *  \code
    7996 *  pyMoleCuilder.SelectionAllMolecules()
     97 *  pyMoleCuilder.wait()
    8098 *  \endcode
    8199 *
     
    84102 *  \code
    85103 *  pyMoleCuilder.SelectAtomById("0")
     104 *  pyMoleCuilder.wait()
    86105 *  \endcode
     106 *
     107 *  \warning Again, take note of the added wait()s that ensure the all enqueued
     108 *  actions also have been executed. This is especially important in scripts as
     109 *  otherwise your script may deadlock. That's because ActionQueue's destructor
     110 *  waits for the thread that executes the actions to end, and in another thread
     111 *  we still want to access to ActionQueue whose instance is however locked as
     112 *  it is about the get destroyed.
    87113 *
    88114 *  \subsection userinterfaces-python-notes-cleanup Cleaning up or reset state ...
     
    115141 *  gives you the docu string on WorldInputAction.
    116142 *
     143 * \subsection userinterfaces-python-notes-wait Waiting for the action queue
    117144 *
    118  * \date 2013-03-18
     145 * Note again that actions are executed in a different thread as the python
     146 * script. Hence, we require synchronization at certain intervals where you
     147 * require molecuilder to be up to speed. All commands you executed such
     148 * as
     149 * \code
     150 * import pyMoleCuilder as mol
     151 * mol.WorldInput("foo.xyz")
     152 * mol.wait()
     153 * \endcode
     154 * just queue this specific input action but not execute it right away. That's
     155 * left to the other thread. Hence, you need to wait() before:
     156 * -# you access mol.get...() functions as these are not actions themselves.
     157 * -# you need to have files written by molecuilder to be parsed in the python
     158 *    script.
     159 *
     160 *
     161 * \date 2013-09-28
    119162 *
    120163 */
Note: See TracChangeset for help on using the changeset viewer.