-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a resource tracker to track and terminate all background proc…
…esses
- Loading branch information
1 parent
5a72ed9
commit 4c319ac
Showing
9 changed files
with
52 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from multiprocessing import Process | ||
from typing import Any, Callable, Dict, Tuple | ||
|
||
from jarvis.modules.database import database | ||
from jarvis.modules.models import models | ||
|
||
db = database.Database(database=models.fileio.base_db) | ||
|
||
|
||
def semaphores( | ||
fn: Callable, | ||
args: Tuple = None, | ||
kwargs: Dict[str, Any] = None, | ||
daemon: bool = False, | ||
) -> None: | ||
"""Resource tracker to store undefined process IDs in the base database and cleanup at shutdown. | ||
Args: | ||
fn: Function to start multiprocessing for. | ||
args: Optional arguments to pass. | ||
kwargs: Keyword arguments to pass. | ||
daemon: Boolean flag to set daemon mode. | ||
""" | ||
process = Process(target=fn, args=args or (), kwargs=kwargs or {}, daemon=daemon) | ||
process.start() | ||
with db.connection: | ||
cursor = db.connection.cursor() | ||
cursor.execute("INSERT INTO children (undefined) VALUES (?);", (process.pid,)) | ||
db.connection.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ | |
"guard", | ||
"surveillance", | ||
"plot_mic", | ||
"undefined", | ||
), | ||
"vpn": ("state",), | ||
"party": ("pid",), | ||
|