comparison env/lib/python3.7/site-packages/galaxy/util/lazy_process.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 import subprocess
2 import threading
3 import time
4
5
6 class LazyProcess(object):
7 """ Abstraction describing a command line launching a service - probably
8 as needed as functionality is accessed in Galaxy.
9 """
10
11 def __init__(self, command_and_args):
12 self.command_and_args = command_and_args
13 self.thread_lock = threading.Lock()
14 self.allow_process_request = True
15 self.process = None
16
17 def start_process(self):
18 with self.thread_lock:
19 if self.allow_process_request:
20 self.allow_process_request = False
21 t = threading.Thread(target=self.__start)
22 t.daemon = True
23 t.start()
24
25 def __start(self):
26 with self.thread_lock:
27 self.process = subprocess.Popen(self.command_and_args, close_fds=True)
28
29 def shutdown(self):
30 with self.thread_lock:
31 self.allow_process_request = False
32 if self.running:
33 self.process.terminate()
34 time.sleep(.01)
35 if self.running:
36 self.process.kill()
37
38 @property
39 def running(self):
40 return self.process and not self.process.poll()
41
42
43 class NoOpLazyProcess(object):
44 """ LazyProcess abstraction meant to describe potentially optional
45 services, in those cases where one is not configured or valid, this
46 class can be used in place of LazyProcess.
47 """
48
49 def start_process(self):
50 return
51
52 def shutdown(self):
53 return
54
55 @property
56 def running(self):
57 return False