How do I interrupt a long task managed by SCons?

拟墨画扇 提交于 2021-01-29 09:27:06

问题


I'm using SCons to manage a Python function long_task() that carries out a long calculation. If I call long_task() directly from a script, then I can interrupt it with Ctrl-C. However, if SCons is running long_task() and I press Ctrl-C, then long_task() continues to run until it completes, and then SCons says "Build interrupted. / building terminated because of errors". Is there a way to make Ctrl-C stop long_task() immediately in this situation?

If I use a signal handler in long_task() to handle SIGINT then it behaves as I want, but I'd rather not have to do this in each of several such long tasks. If I press Ctrl-\ then both longtask() and SCons exit immediately, but this seems rather drastic.

I'm using SCons 3.0.1 and Python 3.6.5 under Ubuntu 18.04.

Here's a minimal SConstruct file:

#!/usr/bin/env python3

import time

def long_task(target, source, env):
    print('Starting long task')
    # Mimic a complex calculation
    for i in range(100):
        time.sleep(0.1)
    print('Finishing long task')

TestBuilder = Builder(action = long_task)

env = Environment(BUILDERS = {'TestBuild': TestBuilder})

env.TestBuild('dummy', [])

回答1:


I highly encourage you to not run long running python logic as an action in a builder. Instead run it via shell as a free standing python program. This also simplifies building a time limit into such program so it doesn't run forever..

Running long running python logic inside SCons will limit parallel builds.

Basically just don't do it..

(BTW. I'm the SCons Project Co-Manager)



来源:https://stackoverflow.com/questions/55754899/how-do-i-interrupt-a-long-task-managed-by-scons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!