Python Forum
How to background another process in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to background another process in Python?
#1
The thing is, I'm trying to get a process inside my script and have me call it whenever I want. For example, I'm filling in some data and I enter the word "background". In this way, it is called a process that is always active. I leave my code in python, I have created a decorator but I get the following error: "EOFError".

Besides that, it should work both ways, when I'm in the background and insert "background", it should return to the main function.

I share with you the code I've been doing:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os, time

def daemonLife(func):
    def wrapper(*args, **kwargs):
        if os.fork(): return
        func(*args, **kwargs)
        os._exit(os.EX_OK)
    return wrapper

@daemonLife
def my_func():
   no_kill_nothing = "Hi!"
   print('pid of it: %d' % os.getppid())
   var2 = str(input("Inside of background!"))
   if var2 == "background":
      main(no_kill_nothing)

def main(text):
   if text == "background":
      my_func()

text = str(input("Insert something"))
main(text)
I tried multi-threading because I think it's more ideal but I haven't been able to.

Thank you very much!
Reply


Messages In This Thread
How to background another process in Python? - by Kalet - Oct-20-2019, 05:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Question about Creating an Automated Process in Python Supratik1234 0 774 Jan-13-2023, 08:29 PM
Last Post: Supratik1234
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 6,566 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Process the image on the Python HTTP server Aleks 0 3,243 Dec-02-2021, 11:43 PM
Last Post: Aleks
  How to to tie the execution of one process to another inside a loop in Python ignorant_wanderer 0 2,065 Jul-11-2020, 03:44 AM
Last Post: ignorant_wanderer
  win32 API: Launch Application to RDP session from background process python script rangeshgupta 0 2,185 May-28-2020, 09:41 PM
Last Post: rangeshgupta
  Spawning a new process that is not attached to python cman234 3 1,950 Apr-25-2020, 05:24 PM
Last Post: cman234
  autostart python scripts in background (Windows10) john36 4 7,772 Oct-01-2019, 01:36 PM
Last Post: john36
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,694 Sep-03-2019, 09:49 PM
Last Post: woooee
  changing the process command line arguments in python Skaperen 3 3,052 Aug-19-2019, 02:40 PM
Last Post: wavic
  random behavriour when handle process termination signal in Python hamzeah 2 2,074 Jul-31-2019, 07:32 AM
Last Post: hamzeah

Forum Jump:

User Panel Messages

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