首页 \ 问答 \ 避免在Matlab GUI中中断回调函数(Avoid interruption of callback functions in Matlab GUI)

避免在Matlab GUI中中断回调函数(Avoid interruption of callback functions in Matlab GUI)

我有一个Matlab GUI,需要很长时间来执行一些回调函数。 此外,这些功能包括以下代码:

 drawnow('expose');
 pause(handles.data.delay);

我想避免那些回调执行被中断,以避免在用户按下其他按钮时数据不一致。 因此,我将图形设置修改为:

set(handles.figure, 'BusyAction','cancel', 'Interruptible','off');

但是,回调仍然中断。 我怎么能避免呢?

注意:我认为问题是我需要将'BusyAction'和'Interruptible'值传播到我GUI中的所有控件,有没有办法自动执行? 例如,在生成GUI之前修改默认值。


I have a Matlab GUI that needs a high time to execute some callback functions. Besides, these functions include the following code:

 drawnow('expose');
 pause(handles.data.delay);

I want to avoid that those callback executions get interrupted in order to avoid data inconsistency if the user presses other buttons. Thus, I modify the figure settings as:

set(handles.figure, 'BusyAction','cancel', 'Interruptible','off');

However, the callbacks are still interrupted. How can I avoid it?

Note: I think that the problem is that I need to propagate the 'BusyAction' and 'Interruptible' values to all the controls in my GUI, is there any way to do it automatically? Like, for example, modifying the default value before generating the GUI.


原文:https://stackoverflow.com/questions/14976907
更新时间:2022-12-24 08:12

最满意答案

如前所述,您可能不需要芹菜。 以下是来自案例2的示例: https//zapier.com/blog/async-celery-example-why-and-how/ 。 它完全为我工作:

from time import sleep
import json
from django.http import HttpResponse
from django.shortcuts import render

def main_view(request):
    return render(request, 'index.html')

def ajax_view(request):
    sleep(10) #This is whatever work you need
    pi1 = "This is pi1" #I just made pi1/pis1 random values
    pis1 = "This is pis1"
    context = {
        "pi1" : pi1,
        "pis1" : pis1,
    }
    data = json.dumps(context)

    return HttpResponse(data, content_type='application/json')

我的index.html包含:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Main View</title>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script>
    $(document).ready(function(){
        $.ajax({
            url: "/test_ajax/",
        }).done(function( data) {
            $("#pi1").text(data.pi1);
            $("#pis1").text(data.pis1); 
        });
    });
</script>
  </head>
  <body>
      <h1 id = "pi1">Loading</h1>
      <h1 id = "pis1">Loading</h1>
  </body>
</html>

我的urls.py包含:

from django.conf.urls import include, url
from django.contrib import admin
from testDjango.test import main_view, ajax_view

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^test/', main_view),
    url(r'^test_ajax/', ajax_view)
]

当我访问localhost时会发生什么:8000 / test /是我立刻看到的:

初次访问

大约10秒后,我看到:

10秒后的图像

这个想法是,你立即返回你的页面,并使用jquery获取操作的结果,每当完成并相应地更新你的页面。 您可以添加更多内容,例如进度条/加载图像等。例如,您可以在后台处理pi1pis ,并在完成后将其加载到HTML中。


As is said previous, you might not need celery. Here's an example derived from case 2 of this: https://zapier.com/blog/async-celery-example-why-and-how/. It's fully working for me:

from time import sleep
import json
from django.http import HttpResponse
from django.shortcuts import render

def main_view(request):
    return render(request, 'index.html')

def ajax_view(request):
    sleep(10) #This is whatever work you need
    pi1 = "This is pi1" #I just made pi1/pis1 random values
    pis1 = "This is pis1"
    context = {
        "pi1" : pi1,
        "pis1" : pis1,
    }
    data = json.dumps(context)

    return HttpResponse(data, content_type='application/json')

My index.html contains:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Main View</title>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script>
    $(document).ready(function(){
        $.ajax({
            url: "/test_ajax/",
        }).done(function( data) {
            $("#pi1").text(data.pi1);
            $("#pis1").text(data.pis1); 
        });
    });
</script>
  </head>
  <body>
      <h1 id = "pi1">Loading</h1>
      <h1 id = "pis1">Loading</h1>
  </body>
</html>

And my urls.py contains:

from django.conf.urls import include, url
from django.contrib import admin
from testDjango.test import main_view, ajax_view

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^test/', main_view),
    url(r'^test_ajax/', ajax_view)
]

What happens when I visit localhost:8000/test/ is that I instantly see:

Initial visit

After about 10 seconds, I then see:

Image after 10 seconds

The idea is that you return your page instantly and use jquery to fetch the result of the operation whenever that's finished and update your page accordingly. You can add more things like progress bars/loading image etc. For your example, you can do the processing for pi1 and pis in the background and load it into the HTML after that's finished.

相关问答

更多
  • Celery有很好的文档,也适用于那些入门的人 ,但有两个事实值得初学者提及: 使用djkombu作为BROKER_BACKEND 。 这将为您提供一个非常简单的开发消息队列,其中所有消息都存储在django使用的SQL数据库中。 由于celery的api,您可以轻松地将其替换为“真实”的消息队列进行生产: BROKER_TRANSPORT = "kombu.transport.django" Django-celery有一个设置CELERY_ALWAYS_EAGER 。 如果设置为True则不会进行异步后 ...
  • 这个问题比我想象的要简单得多 - 不正确的文档! Celery文档要求我们使用CELERY_DEFAULT_QUEUE在celery对象上设置task_default_queue配置。 参考: http : //docs.celeryproject.org/en/latest/userguide/configuration.html#new-lowercase-settings 我们当前应该使用CELERY_TASK_DEFAULT_QUEUE 。 这是所有其他设置名称命名的不一致。 它是在Github上提 ...
  • 你可以限制工作人员的任务,我假设你只需要一个工人,所以在调用djcelery时只需要启动一个工人。 python manage.py celery worker -B --concurrency=1 You can limit the tasks workers, in your cause i assume you just need one worker at time, so just start one worker when calling the djcelery. python manage ...
  • 错误的任务名称 。 通过将任务修饰器更改为@celery_app1.task(name='tasks.rank_all')并调整我的节拍计划以包含正确的名称来解决此问题: CELERYBEAT_SCHEDULE = { 'tasks.rank_all': { 'task': 'tasks.rank_all', 'schedule': timedelta(seconds=30), }, } Wrong task name. This got fixed by ...
  • 你有import djcelery; djcelery.setup_loader() import djcelery; djcelery.setup_loader()在你的settings.py ? 您可以通过运行以下命令找出它尝试连接的位置: $ python manage.py celeryctl shell >>> celery.broker_connection().as_uri() 'setup_loader'非常重要,所以你必须确保你包含它。 (好消息是,芹菜将支持版本2.7的Djang ...
  • 如前所述,您可能不需要芹菜。 以下是来自案例2的示例: https : //zapier.com/blog/async-celery-example-why-and-how/ 。 它完全为我工作: from time import sleep import json from django.http import HttpResponse from django.shortcuts import render def main_view(request): return render(reques ...
  • 来自http://celery.readthedocs.org/en/latest/getting-started/brokers/redis.html : 监视事件(由花和其他工具使用)是全局的,不受虚拟主机设置的影响。 这是由Redis的限制引起的。 Redis PUB / SUB通道是全局的,不受数据库编号的影响。 这似乎是Redis的一个警告:( From http://celery.readthedocs.org/en/latest/getting-started/brokers/redis.ht ...
  • 该错误告诉您它无法序列化整个request以将其发送到任务。 但是,您在请求中使用的唯一事物是用户对象。 您应该只发送用户ID,并在任务中获取对象本身。 export_cases_palu.delay(user_id=request.user.id) ... def export_cases_palu(user_id): user = User.objects.get(id=user_id) d = Context({'username': user.username}) (另外,你不 ...
  • 我解决了这个问题,但我不确定如何。 第二天,我回到了这个确切的配置,任务正在向芹菜工人提出。 也许我重启的服务之一就是关键,但我不确定。 如果有其他人遇到此问题,尤其是在Windows上:确保您的redis-server处于活动状态,并且您可以看到来自ping和任务的传入连接。 在发布此问题之前我已经这样做了,但似乎可能是错误配置的候选人。 I got around this, but I'm not sure how. I came back to this exact configuration the ...
  • Celery中的周期性任务非常类似于此。 有一个专门的调度程序( celery beat ),只需在到期时发送任务。 您还可以通过celery.beat.Scheduler类来创建新的调度程序以用于beat ,您也可以通过celery.beat.Scheduler来创建自定义日程表(如已内置的crontab日程表)。 django-celery扩展( djcelery.schedulers.DatabaseScheduler )中有一个数据库支持的调度程序实现,它使用许多技巧来避免过于频繁地轮询数据库等等( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。