如何停止Django线程


                    

我有一个使用Jquery和Python的网站。</ p>

我有一个执行python函数的Ajax请求。 在Python函数内部,与Linux的接口执行C ++库。</ p>

我遇到的问题是当我创建两个请求以通过Python从AJAX执行此C ++库时。 C ++任务最多可能需要2分钟才能加载。 这很好,但是当我离开当前页面时,由于上一个任务在技术上尚未完成,Django不会加载新页面。</ p>

有什么方法可以确定页面是否在导航,如果是,则调用python停止其功能,以便获得响应。</ p>

我想到的一种方法是线程化,但是,如果我在线程仍在执行的同时导航,则执行该方法时,即使我不在调用请求的页面上,我也可以从调试器中看到它返回了数据。 </ p>

任何人都没有任何想法,如何在离开当前页面的导航时获取python杀死所有线程。</ p>

欢呼</ p>
     </ div>

展开原文

原文

I have a website that uses Jquery and Python.

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.

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.

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.

Cheers

1个回答


似乎您需要异步执行“阻塞”的C ++ Lib。 有几种解决此类问题的方法,但是IMO线程推导性地认为是错误的方法。</ p>

一种方法是使用异步Web服务器(例如 Tornado )来处理异步请求。 另一个(也是我更喜欢的一个)是使用 Celery 。 </ p>
     </ div>

展开原文

原文

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...

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐