如何停止Django的主题 [英] How to Stop Django Thread

查看:106
本文介绍了如何停止Django的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jQuery和Python的一个网站。

I have a website that uses Jquery and Python.

我有一个Ajax请求执行一个Python函数。里面的Python函数有一个是执行一个C ++库与Linux的界面。

I have an Ajax Request that performs a python function. Inside the Python Function there is an interface with Linux that executes a C++ Library.

我遇到的问题是,当我创建了两个请求通过Python来执行这个C ++库从阿贾克斯。 C ++的任务可能需要大约2分钟加载。这是好的但是当我导航离开当前页面,因为previous任务在技术上没有完成的Django不会加载我一个新的页面。

The problem I am having is when I create two requests to execute this C++ Library from AJAX via Python. The C++ Task could take upto 2 minutes to load. This is fine however when I navigate away from the current page since the previous task has technically not completed Django will not load me a new page.

有没有什么办法可以determaine如果页面导航路程,如果是的话,然后调用蟒蛇停止其功能,这样我就可以有一些反应。

Is there any way I can determaine if the page is navigating away and if so then invoke python to stop its function so I can have some responsiveness.

我还以为不过是线程,当我执行这种方法,如果我浏览程,而线程仍在执行,我可以从它返回,即使我​​不是那个叫请​​求的页面上的数据的调试器看到的一种方式。

One way I have thought of is threading however when I perform this approach if i Navigate away while a thread is still executing I can see from the debugger that it returns data even if I am not on the page that called the request.

因此​​,没有人有任何想法我如何能得到蟒蛇杀死在导航的所有主题远离其当前页面。

So does anyone have any ideas how I can get python to kill all threads upon navigation away from its current page.

干杯

推荐答案

好像你需要一个异步执行你的堵的C ++库。有几种方法对这类问题,但IMO线程是​​恭敬地错了......

Seems like you need an asynchronous execution for your "blocking" C++ Lib. There are several approaches for this kind of problems but IMO threading is deferentially the wrong one...

一种方法是使用异步Web服务器如龙卷风来处理异步请求。其他(和一个我喜欢更多)是使用芹菜

One approach is to use an asynchronous web server like Tornado to handle asynchronous requests. The other (and the one I like more) is to use Celery.

这篇关于如何停止Django的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆