Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/galaxy/util/lazy_process.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
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 |