UbuntuServer 16.04 LTS system

After launch:

root @ webserv: / home / user # python3 script.py

# -*- coding: utf-8 -*- import multiprocessing as mp import sys import signal def main(): name = mp.current_process().name print(name+' Starting') if __name__ == '__main__': mp.freeze_support() mp.set_start_method('spawn') p_main = mp.Process(target=main) p_main.start() p_main.join() print('Скрипт завершает работу') print(p_main, p_main.is_alive()) #<Process(Process-1, stopped)> False print(mp.current_process().name) #MainProcess sys.exit() 

And the script goes into perpetual waiting mode.

Who faced? Like everything according to the instructions from the official. site. It can of course matter in Linux and Python, but I do not even know which way to look.

UPD: The script ends when you comment out p_main.join (). But this leads to a malfunction.

UPD: If I add to the end of the process (i.e. I kill it forcibly after the completion of logic)

  os.killpg(mp.current_process().pid, signal.SIGTERM) 

then everything works out. Conclusion: the processes themselves are not completed.

Closed due to the fact that off-topic participants jfs , andreymal , Cheg , Sergey Gornostaev , Nick Volynkin Oct 5 '17 at 4:44 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - jfs, andreymal, Cheg, Sergey Gornostaev, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • I can assume that the problem lies in the fact that the main function is somehow blocking code that runs indefinitely. Something like "while True". Actually, the above example works quite normally, since the function fulfills the entire code and leaves normally - Yaroslav Surzhikov
  • one
    On Ubuntu 16.04.1 LTS and Python 3.5.2 - the above code works as expected: Process-1 Starting -> Скрипт завершает работу -> <Process(Process-1, stopped)> False -> MainProcess - Yaroslav Surzhikov
  • As you can see, there is no blocking code in main. There is only the output of the name of the process being executed. This is most likely a feature of the Ubuntu Server OS, and a Python interpreter for it. As written in the office. documentation, processes after execution should be completed by themselves and transfer control to the main one. But in Linux, I have to kill him at the end of the code of each process. The question is rather more about Python features. Is this normal, is there a threat of memory leakage and how to solve this problem. PS I checked the operation of this script on Windows, and there everything works without the final code. - Alex Y.
  • one
    No, my code normally goes back to the console, ubunt is also server. By the way, the only thing I changed was replacing import os with import sys - Yaroslav Surzhikov
  • one
    The code in question works as is (started, exited) on Ubuntu 16.04 ( python -mplatform -> Linux-4.4.0-96-generic-x86_64-with-Ubuntu-16.04-xenial , python3 -V -> Python 3.5.2) - jfs

0