简体   繁体   English

如何使用在不同控制台中运行的另一个脚本停止正在运行的脚本?

[英]How to stop a running script using another script that's running in a different console?

My aim is to halve the time to find the answer but if a script finds the answer then I want it to stop the other running script as well but I don't know how to do this and have been searching for ages... :'( 我的目的是将时间减少一半,但是如果一个脚本找到了答案,那么我也希望它也停止其他正在运行的脚本,但是我不知道该怎么做,并且已经寻找了很多年龄...: “(

Here is some context: I am trying to find a particular triangular number which has over 1000 divisors and would like to run a script that checks incrementally odd triangular numbers and run another script that checks the even cases, effectively dual processing my way to get the answer! 这里是一些情况:我试图找到一个特定的三角数,该三角数具有1000个除数,并且想要运行一个脚本来检查递增的奇数三角数,并运行另一个脚本来检查偶数情况,有效地双重处理了我的方法回答!

Thank you in advance! 先感谢您!

An example of a desired outcome: 预期结果的示例:

script_evens has found the answer. script_evens找到了答案。

script_evens executes command that stops script_odds. script_evens执行停止script_odds的命令。

Sounds like you're trying to reinvent the wheel of multithreading. 听起来您正在尝试重塑多线程。 What you really want is a single process that spawns multiple processes, and then kills them when one of them finds an answer. 您真正想要的是一个进程,它产生多个进程,然后在其中一个找到答案时将其杀死。 Multithreading/multiprocessing can be complicated and is probably beyond the scope of this answer, but here's a short starter tutorial in python: https://blog.usejournal.com/multithreading-vs-multiprocessing-in-python-c7dc88b50b5b 多线程/多处理可能很复杂,并且可能超出了此答案的范围,但这是python中的简短入门教程: https : //blog.usejournal.com/multithreading-vs-multiprocessing-in-python-c7dc88b50b5b

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

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