简体   繁体   English

Python脚本在Google vm上手动运行,但是如果在真正的循环中进行调度会被杀死

[英]Python script runs manually on google vm, but gets killed if put in while true loop for scheduling

I have a python script that runs fine when I run it via python3 script.py & on the the google vm, but then when i detach it with a screen and leave it run a couple iterations on its own I come back to check and it gets killed. 当我通过python3 script.py &在google vm上运行它时,我有一个运行良好的python脚本,但是当我用screen将其分离并自行运行几个迭代时,我会再次检查它被杀。

I think it might be something to do with high cpu usage, i tried to do a while true loop and sleep the program for a while, then i tried to use apscheduler or just scheduler or even nice -n 19 python3 script.py but neither worked out, the thing is that the script seems to run fine the first time or even first two times, but then it gets killed. 我认为这可能与cpu使用率高有关,我尝试执行一会儿true循环并使程序休眠一会儿,然后尝试使用apscheduler或仅使用scheduler甚至是nice -n 19 python3 script.py但都没有得出的结论是,脚本似乎在第一次甚至两次都运行良好,但随后被杀死。

Here is how I run my script, is there anyway i can solve this without upping my CPU? 这是我运行脚本的方式,是否可以在不增加CPU的情况下解决此问题? I think I have a small machine on vm. 我想我在vm上有一台小机器。

schedule.every(10).minute.do(scheduled_job)
print('STARTED PROGRAM')

while True:
    schedule.run_pending()
    time.sleep(1)

Use /usr/bin/time --verbose python3 script.py to measure memory used by a single job run, or use ps axu or top to do that for a continuously looping task. 使用/usr/bin/time --verbose python3 script.py来测量单个作业运行所使用的内存,或者使用ps axutop来执行连续循环任务。 Verify that you malloc less than the VM container agrees to provide. 验证您的分配少于VM容器同意提供的数量。

If you see your process killed while testing on a small linux host, look for clues in the log: $ zgrep oom /var/log/{syslog,messages}* 如果您在小型Linux主机上进行测试时发现进程被杀死,请在日志中查找线索: $ zgrep oom /var/log/{syslog,messages}*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM