Example #1
0
def mainiteration(block=True):
    debug.mainthreadTest()
    if mainthreadGUI.inside_idle_callback and thread_enable.query():
        gtk.gdk.threads_enter()
    try:
        gtk.main_iteration(block)
    finally:
        if mainthreadGUI.inside_idle_callback and thread_enable.query():
            gtk.gdk.threads_leave()
Example #2
0
def mainiteration(block=True):
     debug.mainthreadTest()
     if mainthreadGUI.inside_idle_callback and thread_enable.query():
          gtk.gdk.threads_enter()
     try:
          gtk.main_iteration(block)
     finally:
          if mainthreadGUI.inside_idle_callback and thread_enable.query():
               gtk.gdk.threads_leave()
Example #3
0
 def __call__(self):
      global inside_idle_callback
      inside_idle_callback = True
      if thread_enable.query():
           gtk.gdk.threads_enter()
      try:
           self.func(*self.args, **self.kwargs)
      finally:
           gtk.gdk.flush()
           if thread_enable.query():
                gtk.gdk.threads_leave()
           inside_idle_callback = False
      return False                  # don't repeat
Example #4
0
 def __call__(self):
     global inside_idle_callback
     inside_idle_callback = True
     if thread_enable.query():
         gtk.gdk.threads_enter()
     try:
         self.func(*self.args, **self.kwargs)
     finally:
         gtk.gdk.flush()
         if thread_enable.query():
             gtk.gdk.threads_leave()
         inside_idle_callback = False
     return False  # don't repeat
Example #5
0
def execute_immortal(function, args=(), kwargs={}):
    if thread_enable.query():
        littlethread = MiniThread(function, args, kwargs)
        littlethread.immortalize()
        littlethread.start()
    else:
        function(*args, **kwargs)
Example #6
0
def execute(function, args=(), kwargs={}):
    if thread_enable.query():
        littlethread = MiniThread(function, args, kwargs)
        littlethread.start()
        return littlethread
    else:
        function(*args, **kwargs)
Example #7
0
def loadLog(menuitem, filename, checkpoints):
    if gtklogger.replaying():
        raise ooferror.ErrUserError(
            "Multiple GUI logs cannot be replayed simultaneously!")
    debug.fmsg("Loading gui script", filename)
    menuitem.root().setOption('post_hook', menucheckpoint)
    dblevel = 0
    if debug.debug():
        dblevel = 3
    #dblevel = 4
    global _replaying
    _replaying = True

    # When replaying, we have to make sure that progress bars *always*
    # appear, so we set the delay time to 0.  If the delay time is
    # non-zero, then a script recorded on a slow machine would insert
    # a checkpoint for opening the activity viewer window, but a
    # faster machine might never open the window, and would wait
    # forever for the checkpoint when replaying the script.
    progressbar_delay.set_delay(None, 0)

    gtklogger.replay(filename,
                     beginCB=activityViewer.openActivityViewer,
                     finishCB=logFinished,
                     debugLevel=dblevel,
                     threaded=thread_enable.query(),
                     exceptHook=loggererror,
                     checkpoints=checkpoints)
Example #8
0
def loadLog(menuitem, filename, checkpoints):
    if gtklogger.replaying():
        raise ooferror.ErrUserError(
            "Multiple GUI logs cannot be replayed simultaneously!")
    debug.fmsg("Loading gui script", filename)
    menuitem.root().setOption('post_hook', menucheckpoint)
    dblevel = 0
    if debug.debug():
        dblevel = 3
    #dblevel = 4
    global _replaying
    _replaying = True

    # When replaying, we have to make sure that progress bars *always*
    # appear, so we set the delay time to 0.  If the delay time is
    # non-zero, then a script recorded on a slow machine would insert
    # a checkpoint for opening the activity viewer window, but a
    # faster machine might never open the window, and would wait
    # forever for the checkpoint when replaying the script.
    progressbar_delay.set_delay(None, 0)

    gtklogger.replay(
        filename,
        beginCB=activityViewer.openActivityViewer,
        finishCB=logFinished,
        debugLevel=dblevel,
        threaded=thread_enable.query(),
        exceptHook=loggererror,
        checkpoints=checkpoints)
Example #9
0
def execute_immortal(function, args=(), kwargs={}):
    if thread_enable.query():
        littlethread = MiniThread(function, args, kwargs)
        littlethread.immortalize()
        littlethread.start()
    else:
        function(*args, **kwargs)
Example #10
0
def delayed_add_ProgressBar(progressid):
    debug.mainthreadTest()
    if thread_enable.query():
        if progressbar_delay.delay < progressbar_delay.period:
            _updatePBdisplayNow(progressid) # immediate display
        else:
            gobject.timeout_add(progressbar_delay.delay,
                                _updatePBdisplay, progressid)
Example #11
0
def delayed_add_ProgressBar(progressid):
    debug.mainthreadTest()
    if thread_enable.query():
        if progressbar_delay.delay < progressbar_delay.period:
            _updatePBdisplayNow(progressid)  # immediate display
        else:
            gobject.timeout_add(progressbar_delay.delay, _updatePBdisplay,
                                progressid)
Example #12
0
def runBlock_gui(func, args=(), kwargs={}):
    if thread_enable.query() and not mainthread.mainthread():
        callbackobj = OOFIdleBlockCallback(func, args, kwargs)
        callbackobj.event.clear()
        gobject.idle_add(callbackobj, priority=gobject.PRIORITY_LOW)
        callbackobj.event.wait()
        return callbackobj.result
    else:
        return func(*args, **kwargs)
Example #13
0
def runBlock_gui(func, args=(), kwargs={}):
    if thread_enable.query() and not mainthread.mainthread():
        callbackobj = OOFIdleBlockCallback(func, args, kwargs)
        callbackobj.event.clear()
        gobject.idle_add(callbackobj, priority=gobject.PRIORITY_LOW)
        callbackobj.event.wait()
        return callbackobj.result
    else:
        return func(*args, **kwargs)
Example #14
0
def getThreadedWorker(menuitem, argtuple, argdict):
    if not thread_enable.query():
        return worker.NonThreadedWorker(menuitem, argtuple, argdict)
    if mainthread.mainthread():
        return worker.ThreadedWorker(menuitem, argtuple, argdict)
    # Threading is enabled, but this isn't the main thread.  We must
    # be running a script, because that is the only way to create
    # workers that don't start on the main thread.  Scripts can't run
    # their commands concurrently, so we need to create a worker that
    # blocks until the command finishes.
    return GUIThreadedWorkerBlock(menuitem, argtuple, argdict)
Example #15
0
def getThreadedWorker(menuitem, argtuple, argdict):
    if not thread_enable.query():
        return worker.NonThreadedWorker(menuitem, argtuple, argdict)
    if mainthread.mainthread():
        return worker.ThreadedWorker(menuitem, argtuple, argdict)
    # Threading is enabled, but this isn't the main thread.  We must
    # be running a script, because that is the only way to create
    # workers that don't start on the main thread.  Scripts can't run
    # their commands concurrently, so we need to create a worker that
    # blocks until the command finishes.
    return GUIThreadedWorkerBlock(menuitem, argtuple, argdict)
Example #16
0
 def show(self):
     debug.mainthreadTest()
     self.canvas.show()
     # Displays which want to show animations will be calling
     # show() many times in one gtk main loop pass.  The display
     # doesn't actually get updated unless events are processed, so
     # we have to call mainiteration() here.  This has the
     # unfortunate side effect of allowing all sorts of button
     # clicks and other user events, so we should be careful to
     # disable the GUI when the program is busy.  Also, calling
     # mainiteration() appears to be a no-no during mouse event
     # callbacks, so we check for that here as well.
     if not thread_enable.query():
         if not gfxwindow.during_callback():
             oof_mainiteration.mainiteration_loop(False)
Example #17
0
 def show(self):
     debug.mainthreadTest()
     self.canvas.show()
     # Displays which want to show animations will be calling
     # show() many times in one gtk main loop pass.  The display
     # doesn't actually get updated unless events are processed, so
     # we have to call mainiteration() here.  This has the
     # unfortunate side effect of allowing all sorts of button
     # clicks and other user events, so we should be careful to
     # disable the GUI when the program is busy.  Also, calling
     # mainiteration() appears to be a no-no during mouse event
     # callbacks, so we check for that here as well.
     if not thread_enable.query():
         if not gfxwindow.during_callback():
             oof_mainiteration.mainiteration_loop(False)
Example #18
0
def getThreadedParallelWorker(menuitem, argtuple, argdict):
    ## parallel workers
    ## only called by front-end
    ## back-end is running on text-mode, without any text
    ## progress bars
    if not thread_enable.query():
        ## if GUI is not in place yet, do not
        ## launch a thread. Instead run a serial
        ## parallel worker
        return worker.ParallelWorker(menuitem, argtuple, argdict)
    if mainthread.mainthread():
        ## if main thread launches a parallel thread
        ## launch a GUI worker
        return GUIParallelThreadedWorker(menuitem, argtuple, argdict)
    ## if subthread is attempting to launch a thread,
    ## block the subthread, until, sub-subthread joins
    return GUIParallelThreadedWorkerBlock(menuitem, argtuple, argdict)
Example #19
0
def getThreadedParallelWorker(menuitem, argtuple, argdict):
    ## parallel workers
    ## only called by front-end
    ## back-end is running on text-mode, without any text
    ## progress bars
    if not thread_enable.query():
        ## if GUI is not in place yet, do not 
        ## launch a thread. Instead run a serial
        ## parallel worker
        return worker.ParallelWorker(menuitem, argtuple, argdict)
    if mainthread.mainthread():
        ## if main thread launches a parallel thread
        ## launch a GUI worker
        return GUIParallelThreadedWorker(menuitem, argtuple, argdict)
    ## if subthread is attempting to launch a thread,
    ## block the subthread, until, sub-subthread joins
    return GUIParallelThreadedWorkerBlock(menuitem, argtuple, argdict)
Example #20
0
def _updatePBdisplayNow(progressid):
    debug.mainthreadTest()
    # Don't do anything unless threads are enabled and the gui has
    # been started.
    if thread_enable.query() and guitop.top():
        prog = progress.findProgressByID(progressid)
        if prog is not None and not (prog.finished() or prog.stopped()):
            # Create just one activity viewer.  If it's been opened
            # and closed already, don't reopen it automatically.
            if not _activityViewerOpened:
                # The newly created Activity Viewer window
                # automatically calls installBar for every existing
                # Progress object, including the one identified by the
                # argument to this routine.
                openActivityViewer()
            else:
                # The Activity Viewer might have been closed, in which
                # case activityViewer is None.
                if activityViewer is not None:
                    activityViewer.addGTKBar(prog)
Example #21
0
def _updatePBdisplayNow(progressid):
    debug.mainthreadTest()
    # Don't do anything unless threads are enabled and the gui has
    # been started.
    if thread_enable.query() and guitop.top():
        prog = progress.findProgressByID(progressid)
        if prog is not None and not (prog.finished() or prog.stopped()):
            # Create just one activity viewer.  If it's been opened
            # and closed already, don't reopen it automatically.
            if not _activityViewerOpened:
                # The newly created Activity Viewer window
                # automatically calls installBar for every existing
                # Progress object, including the one identified by the
                # argument to this routine.
                openActivityViewer()
            else:
                # The Activity Viewer might have been closed, in which
                # case activityViewer is None.
                if activityViewer is not None:
                    activityViewer.addGTKBar(prog)
Example #22
0
def rerecordLog(menuitem, filename, checkpoints, use_gui):
    if gtklogger.replaying():
        raise ooferror.ErrUserError(
            "Multiple GUI logs cannot be replayed simultaneously!")
    menuitem.root().setOption('post_hook', menucheckpoint)
    dblevel = 0
    if debug.debug():
        dblevel = 3
    #dblevel = 4
    global _replaying, _recording
    _replaying = True
    _recording = True
    progressbar_delay.set_delay(None, 0)

    # Find a suitable new name for the backup copy of the old log
    # file.  Just append ".bak", but if that file already exists,
    # append ".bakX", where X is an integer.
    if not os.path.exists(filename + '.bak'):
        backupname = filename + '.bak'
    else:
        backupname = None
        count = 2
        while not backupname:
            trialname = "%s.bak%d" % (filename, count)
            if not os.path.exists(trialname):
                backupname = trialname
            count += 1
    os.system('cp ' + filename + ' ' + backupname)
    debug.fmsg("Loading gui script", backupname)

    gtklogger.replay(
        backupname,
        beginCB=activityViewer.openActivityViewer,
        finishCB=logFinished,
        debugLevel=dblevel,
        threaded=thread_enable.query(),
        exceptHook=loggererror,
        rerecord=filename,
        checkpoints=checkpoints,
        logger_comments=use_gui
    )  #Passing the logger_comments parameter to show the loggergui
Example #23
0
def rerecordLog(menuitem, filename, checkpoints, use_gui):
    if gtklogger.replaying():
        raise ooferror.ErrUserError(
            "Multiple GUI logs cannot be replayed simultaneously!")
    menuitem.root().setOption('post_hook', menucheckpoint)
    dblevel = 0
    if debug.debug():
        dblevel = 3
    #dblevel = 4
    global _replaying, _recording
    _replaying = True
    _recording = True
    progressbar_delay.set_delay(None, 0)

    # Find a suitable new name for the backup copy of the old log
    # file.  Just append ".bak", but if that file already exists,
    # append ".bakX", where X is an integer.
    if not os.path.exists(filename + '.bak'):
        backupname = filename + '.bak'
    else:
        backupname = None
        count = 2
        while not backupname:
            trialname = "%s.bak%d" % (filename, count)
            if not os.path.exists(trialname):
                backupname = trialname
            count += 1
    os.system('cp '+filename+' '+backupname)
    debug.fmsg("Loading gui script", backupname)

    gtklogger.replay(
        backupname,
        beginCB=activityViewer.openActivityViewer,
        finishCB=logFinished,
        debugLevel=dblevel,
        threaded=thread_enable.query(),
        exceptHook=loggererror,
        rerecord=filename,
        checkpoints=checkpoints,
        logger_comments=use_gui) #Passing the logger_comments parameter to show the loggergui
Example #24
0
def run(no_interp=None):
    global _rank
    global startupfiles

    process_inline_options()  # execute well-formed oof options

    # Look for .oof2rc in the user's home directory.
    if not no_rc:
        oofrcpath = os.path.join(os.path.expanduser("~"), ".oof2rc")
        if os.path.exists(oofrcpath):
            startupfiles = [StartUpScriptNoLog(oofrcpath)]+startupfiles


    if thread_enable.query() and not (runtimeflags.text_mode or config.no_gui()):
        # TODO: Is this still necessary?
        garbage.disable()               # work-around for gtk bug?

    start_parallel_machine()  # start parallel suite (if available)

    if _rank == 0:
        if parallel_enable.enabled():
            from ooflib.SWIG.common import mpitools
            _size = mpitools.Size()
            mpitools.Isend_Bool(thread_enable.enabled(), range(1,_size))
            
        if parallel_enable.enabled():
            from ooflib.common.IO import socket2me

        if config.petsc():
            print "Going to InitPETSc"
            from ooflib.SWIG.engine.PETSc.petsc_solverdriver import InitPETSc
            InitPETSc(sys.argv)
            for s in sys.argv:
                print s

        start_sockets_Front_End()
        # Import mainmenu only *after* processing command line options, so
        # that the options can affect which menus are loaded.
        global mainmenu
        from ooflib.common.IO import mainmenu
        front_end(no_interp)  # all non-parallel menu items are executed here.
    else:
        # parallel back-end
        parallel_enable.set(True)  # notify back-end of its parallel status

        # thread status at the back-ends
        from ooflib.SWIG.common import mpitools
        thread_enable.set(mpitools.Recv_Bool(0))
        if not thread_enable.enabled():
            lock.disable_all()
        
        if parallel_enable.enabled():
            from ooflib.common.IO import socket2me

        if config.petsc():
            print "Going to InitPETSc"
            from ooflib.SWIG.engine.PETSc.petsc_solverdriver import InitPETSc
            InitPETSc(sys.argv)
            for s in sys.argv:
                print s

        debug.set_debug_mode()  # set for debugging parallel mode
        from ooflib.common import quit
        quit.set_quiet() ## back-end exits quietly.
        start_sockets_Back_End()  # socket initialization
        from ooflib.common import backEnd  # import back end machine
        # The back end shouldn't run the gui!
        runtimeflags.text_mode = True
        backEnd.back_end()  # back-end awaits for your command
Example #25
0
def subthreadTest():
    if _debug_mode:
        if thread_enable.query() and mainthread.mainthread():
            fmsg("IN MAIN THREAD")
            dumpTrace()
            os.abort()
Example #26
0
File: oof.py Project: creuzige/OOF2
def run(no_interp=None):
    global _rank
    global startupfiles

    process_inline_options()  # execute well-formed oof options

    # Look for .oof2rc in the user's home directory.
    if not no_rc:
        oofrcpath = os.path.join(os.path.expanduser("~"), ".oof2rc")
        if os.path.exists(oofrcpath):
            startupfiles = [StartUpScriptNoLog(oofrcpath)] + startupfiles

    if thread_enable.query() and not (runtimeflags.text_mode
                                      or config.no_gui()):
        # TODO: Is this still necessary?
        garbage.disable()  # work-around for gtk bug?

    start_parallel_machine()  # start parallel suite (if available)

    if _rank == 0:
        if parallel_enable.enabled():
            from ooflib.SWIG.common import mpitools
            _size = mpitools.Size()
            mpitools.Isend_Bool(thread_enable.enabled(), range(1, _size))

        if parallel_enable.enabled():
            from ooflib.common.IO import socket2me

        if config.petsc():
            print "Going to InitPETSc"
            from ooflib.SWIG.engine.PETSc.petsc_solverdriver import InitPETSc
            InitPETSc(sys.argv)
            for s in sys.argv:
                print s

        start_sockets_Front_End()
        # Import mainmenu only *after* processing command line options, so
        # that the options can affect which menus are loaded.
        global mainmenu
        from ooflib.common.IO import mainmenu
        front_end(no_interp)  # all non-parallel menu items are executed here.
    else:
        # parallel back-end
        parallel_enable.set(True)  # notify back-end of its parallel status

        # thread status at the back-ends
        from ooflib.SWIG.common import mpitools
        thread_enable.set(mpitools.Recv_Bool(0))
        if not thread_enable.enabled():
            lock.disable_all()

        if parallel_enable.enabled():
            from ooflib.common.IO import socket2me

        if config.petsc():
            print "Going to InitPETSc"
            from ooflib.SWIG.engine.PETSc.petsc_solverdriver import InitPETSc
            InitPETSc(sys.argv)
            for s in sys.argv:
                print s

        debug.set_debug_mode()  # set for debugging parallel mode
        from ooflib.common import quit
        quit.set_quiet()  ## back-end exits quietly.
        start_sockets_Back_End()  # socket initialization
        from ooflib.common import backEnd  # import back end machine
        # The back end shouldn't run the gui!
        runtimeflags.text_mode = True
        backEnd.back_end()  # back-end awaits for your command
Example #27
0
def subthreadTest():
    if _debug_mode:
        if thread_enable.query() and mainthread.mainthread():
            fmsg("IN MAIN THREAD")
            dumpTrace()
            os.abort()