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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿