2

I have a python program where I made a new process using multiprocessing but the function doesn't seem to run after FreeConsole() "check" is printed but after that none of the codes work under the sendme() and the main function works after it. actually i want the function sendme to run in the background without console

import multiprocessing as mp
def sendme():      
    import win32console as con
    print("check")
    con.FreeConsole()
    f=open ("hello2.txt",'w')
    f.close()

if name=="__main__":
    p=mp.Process(target=sendme)
    p.start()
    print ("main")
Ondrej K.
  • 8,841
  • 11
  • 24
  • 39
hitesh kumar
  • 421
  • 5
  • 8

1 Answers1

0

The easiest way to Use the shebang line in your python script. Make it executable using the command,

chmod +x python_script.py

Use no hangup to run a program in background even if you close your terminal.

nohup /path/to/python_script.py &

OR

  python /path/to/python_script.py &

Do not forget to use & to put it in background.

To see the process again, use in terminal,

ps ax | grep python_script.py

OR

$ jobs
[1]+  Running                 nohup python_script.py & 

If you are using windows then:

On Windows this can be achieved with the pythonw.exe executable. This will run your program in the background, with no visible process or way to interact with it. You also cannot terminate it without a system monitor.. You can check for the details here pythonw.exe or python.exe?

Karn Kumar
  • 8,518
  • 3
  • 27
  • 53
  • The OP seems to be suffering from Windows. – tripleee Jul 22 '18 at 13:28
  • @tripleee, uhh! i did not realise that :) – Karn Kumar Jul 22 '18 at 13:28
  • thing is my goal is to make it into exe then when double clicked i want just one function to run in background for that function i used process and freeconsole because the victim obviosly doesnt wants to run it in background. plz help thanks – hitesh kumar Jul 22 '18 at 14:35