Python到PHP strang

2024-10-02 06:24:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望有人能帮我。:)

我从PHP调用了一个python脚本,在phpseclib/ssh2的帮助下,我将ssh连接到我的服务器上,它运行良好。你知道吗

我的问题是如果我用时间。睡眠(5) “在python脚本的循环中,我没有得到返回的结果,但是如果我删除时间。睡眠(5) 以及时间。睡眠(3) 它起作用了。你知道吗

有人知道为什么会这样吗?你知道吗

如果我尝试python脚本,我的控制台一切都是完美的。!你知道吗

items = [
    '1',
    '2',
    '3'
]
    itemArray = {}
    def checker():
        for item in items:
            time.sleep(5) # If added not working, if removed working, result gets send back
            position = 1  # keeps track of the ranking position
            for start in range(int(deep)):
                time.sleep(3)
                results = 'something'
                for div in results:
                    try:
                        if div.find('i', href=True)['href'].find(something) != -1:
                            exit_conditon = True
                            break
                        else:
                            position += 1
                    except:
                        print "Unexpected error:", sys.exc_info()[0]
                        raise
                if 'exit_conditon' in locals():
                    if exit_conditon is True:
                        exit_conditon = False
                        itemArray.update({value: 1})
                        break

        sys.exit(itemArray)
    checker() 

请帮忙。你知道吗

更新:如果items数组中有3行,则需要删除第二行时间。睡眠(5) 为了让它工作,如果我的数组中有2个项目,我只需要删除第一个时间。睡眠(5). 你知道吗


Tags: in脚本trueforiftime时间exit
2条回答

这取决于脚本执行所需的时间。如果您的脚本(php+python)使用默认配置所花费的时间超过30秒,那么php会杀死它。你知道吗

只需在php代码的开头添加set_time_limit(120)

http://php.net/manual/en/function.set-time-limit.php

如果在同一台服务器上执行php和python脚本,应该使用execshell_exec。这样会更快。见php shell_exec() vs exec()

这个脚本现在正像我应该做的那样工作:)感谢“纽伯特”的回答。你知道吗

如果我将$ssh->;setTimeout()设置为unlimited,那么如果脚本在某个点停止,我还能得到一个响应吗?你知道吗

相关问题 更多 >

    热门问题