Skip to content

Commit 76ba97f

Browse files
committed
working release
1 parent 61a004c commit 76ba97f

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.python_manager.log
2+
__pycache__
3+
*/__pycache__

manager.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
#!/bin/python
22
import logging as log
3+
from importlib import import_module
4+
import services
5+
import config
6+
from modules.worker import Worker
37

48
LOG_FILENAME = 'python_manager.log'
9+
dynamic_imports = []
10+
worker = Worker()
11+
12+
class Service():
13+
def __init__(self, name):
14+
self.name = name
515

616
def __init__():
17+
global dynamic_imports
718
log.basicConfig(filename=LOG_FILENAME,level=log.DEBUG)
19+
for service in config.run.keys():
20+
dynamic_imports.append(import_module('services.%s' %service))
821

922
def main():
1023
__init__()
11-
log.warning("lol")
24+
for service_name in config.run.keys():
25+
worker.add(Service(service_name))
26+
worker.start()
27+
log.info('All tasks done. Stopping')
1228
return 0
1329

1430
if __name__ == '__main__':

modules/worker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from threading import Thread
2+
import services
3+
4+
class Worker():
5+
def __init__(self):
6+
self.threads = []
7+
self.services = []
8+
9+
def run_service(self, service):
10+
eval("services.%s.main()" %service.name)
11+
12+
def start(self):
13+
for service in self.services:
14+
t = Thread(target=self.run_service, args=[service])
15+
self.threads.append(t)
16+
t.start()
17+
18+
def add(self, service):
19+
self.services.append(service)
20+
21+

services/hello_world.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/python
2+
3+
def main(args=None):
4+
print("hello world")
5+
return 0
6+
7+
if __name__ == "__main__":
8+
main()

0 commit comments

Comments
 (0)