weixin_33725270 2011-11-22 22:23 采纳率: 0%
浏览 512

如何停止Django线程

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条回答

  • weixin_33693070 2011-11-23 14:32
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog