Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop execution of a module
#1
Hello everybody,

I have the following problem:
I have two scripts:
The main script:
import multiprocessing
import time
import module

def runModule():
    module


def main():
    p = multiprocessing.Process(target=runModule)
    p.start()
    time.sleep(10)
    p.terminate()


if __name__ == '__main__':
    main()
and the module script:
from time import sleep

for i in range(100):
    print i
    sleep(1)
The problem is the running module doesn't stop after 10s.
Is there any way to solve this?
Thank you !
Reply
#2
from time import sleep
import multiprocessing
import time
 
def runModule():
    module()
 
 
def main():
    p = multiprocessing.Process(target=runModule)
    p.start()
    time.sleep(10)
    p.terminate()

def module():
    for i in range(100):
        print (i)
        sleep(1)
 
 
if __name__ == '__main__':
    main()
Reply
#3
I don't want to include the code from the module inside the main file. What I want is to run the module file and to stop execution from the main thread.
Reply
#4
your file and method has same name(module)

try

from time import sleep
def run_module():
    for i in range(100):
        print (i)
        sleep(1)
from time import sleep
import multiprocessing
import time
import module
 
def runModule():
    module.run_module()
 
def main():
    p = multiprocessing.Process(target=runModule)
    p.start()
    time.sleep(10)
    p.terminate()
 
if __name__ == '__main__':
    main()
Reply
#5
Thank you very much! Can I apply this to my program without calling a specific function from the module? If I replace the module with a python program can I run it and stop it from my script ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  fraction module: can you stop the reducing? qmfoam 1 2,399 Oct-10-2020, 06:10 PM
Last Post: bowlofred
  Pythone module for dynamic rule execution hemal07yc 1 8,987 Sep-13-2019, 11:25 AM
Last Post: luoheng

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020