This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactered fork (might be broken)
- Loading branch information
Showing
13 changed files
with
521 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +0,0 @@ | ||
import logging | ||
from pidantic.pidfork import PIDanticFork | ||
|
||
|
||
_pidantic_classes = {} | ||
_pidantic_classes['fork'] = PIDanticFork | ||
|
||
|
||
def pidantic_factory(pid_string, event_callback, log=logging, use_channel=False, channel_is_stdio=False, **kwargs): | ||
""" | ||
Create an object with the PIDantic interface. The specific type of object created will depend on the pid_string | ||
argument. | ||
Parameters | ||
pid_string: | ||
The pid string has the following format: | ||
<driver name>:<driver specific string> | ||
In the case of the fork driver an example string were the program "/bin/true" is run would be: | ||
fork:/bin/true | ||
the keywords are driver specific as well. | ||
event_callback: | ||
This is a function with the signature callback(PIDantic, PIDanticEvents). It is called whenever events o | ||
log: | ||
A python logging object for recording events specific to the operation of this library. It does not record | ||
events in the process being run | ||
use_channel: | ||
Establish a special communication channel between this object and the child process that ill be run. How | ||
the channel is created is driver specific. In the fork driver it is a pipe to the child process. In | ||
XXXX supervisord it will use a file, or a header on the stdio output. TBD | ||
channel_is_stdio | ||
A boolean that determines if the channel will be the exact same thing as stdout/stdin. There are times when | ||
a child process may be willing to use special handling code for messaging with its supervisor and times when | ||
it may not. This features allows the channel messaging to code to operate in the same way for the parent | ||
process when dealing with a channel aware process and a process that will just go through stdio. | ||
Keyword Arguments: | ||
These are determined by the driver. supD will likely need arguments to determine if a new sup must be start | ||
or the unix domain socket to an existing supD etc. | ||
""" | ||
|
||
|
||
ndx = pid_string.find(":") | ||
if ndx < 0: | ||
return None | ||
|
||
driver_name = pid_string[:ndx] | ||
argv = pid_string[ndx + 1:] | ||
|
||
global _pidantic_classes | ||
PIDClass = _pidantic_classes[driver_name] | ||
if not PIDClass: | ||
return None | ||
|
||
pidantic = PIDClass(argv, event_callback, log=log, use_channel=use_channel, channel_is_stdio=channel_is_stdio) | ||
|
||
return pidantic | ||
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,21 @@ | ||
from pidantic.fork.pidfork import PIDanticFork | ||
from pidantic.pidbase import _set_param_or_default | ||
|
||
class ForkPidanticFactory(object): | ||
|
||
driver_name = "fork" | ||
|
||
def __init__(self, **kwvals): | ||
pass | ||
|
||
def get_pidantic(self, **kwvals): | ||
|
||
cb = _set_param_or_default(kwvals, "event_callback") | ||
argv = _set_param_or_default(kwvals, "argv") | ||
log = _set_param_or_default(kwvals, "log") | ||
pidfork = PIDanticFork(argv, event_callback=cb, log=log, kwargs) | ||
pidfork.start() | ||
return pidfork | ||
|
||
def stored_instances(self): | ||
return [] |
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,70 @@ | ||
import tempfile | ||
from pidantic.supd.pidsupd import SupDPidanticFactory | ||
|
||
__author__ = 'bresnaha' | ||
|
||
import unittest | ||
|
||
class PIDSupBasicTest(unittest.TestCase): | ||
|
||
def simple_api_walk_through_test(self): | ||
|
||
tempdir = tempfile.mkdtemp() | ||
factory = SupDPidanticFactory(directory=tempdir, name="tester") | ||
pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory='tempdir') | ||
state = pidantic.get_state() | ||
while not pidantic.is_done(): | ||
factory.poll() | ||
factory.terminate() | ||
|
||
def simple_cleanup_test(self): | ||
|
||
tempdir = tempfile.mkdtemp() | ||
factory = SupDPidanticFactory(directory=tempdir, name="tester") | ||
pidantic = factory.get_pidantic(command="/bin/sleep 1", process_name="sleep", directory='tempdir') | ||
state = pidantic.get_state() | ||
while not pidantic.is_done(): | ||
factory.poll() | ||
pidantic.cleanup() | ||
factory.terminate() | ||
|
||
def simple_return_code_success_test(self): | ||
|
||
tempdir = tempfile.mkdtemp() | ||
factory = SupDPidanticFactory(directory=tempdir, name="tester") | ||
pidantic = factory.get_pidantic(command="/bin/true", process_name="true", directory='tempdir') | ||
while not pidantic.is_done(): | ||
factory.poll() | ||
rc = pidantic.get_result_code() | ||
self.assertEqual(rc, 0) | ||
factory.terminate() | ||
|
||
def simple_return_code_success_test(self): | ||
|
||
tempdir = tempfile.mkdtemp() | ||
factory = SupDPidanticFactory(directory=tempdir, name="tester") | ||
pidantic = factory.get_pidantic(command="/bin/false", process_name="false", directory='tempdir') | ||
while not pidantic.is_done(): | ||
factory.poll() | ||
rc = pidantic.get_result_code() | ||
self.assertNotEqual(rc, 0) | ||
factory.terminate() | ||
|
||
def two_processes_one_sup_test(self): | ||
|
||
tempdir = tempfile.mkdtemp() | ||
factory = SupDPidanticFactory(directory=tempdir, name="tester") | ||
false_pid = factory.get_pidantic(command="/bin/false", process_name="false", directory='tempdir') | ||
true_pid = factory.get_pidantic(command="/bin/false", process_name="false", directory='tempdir') | ||
while not false_pid.is_done() or not true_pid.is_done(): | ||
factory.poll() | ||
rc = false_pid.get_result_code() | ||
self.assertNotEqual(rc, 0) | ||
rc = true_pid.get_result_code() | ||
self.assertEqual(rc, 0) | ||
factory.terminate() | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
Oops, something went wrong.