-
Notifications
You must be signed in to change notification settings - Fork 1
/
result.py
36 lines (28 loc) · 843 Bytes
/
result.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from enum import Enum
from snuqs.buffer import Buffer
from typing import Dict
import threading
class Result:
class Status(Enum):
CREATED = 1
RUNNING = 2
DONE = 3
def __init__(self, thread: threading.Thread, ret: Dict[str, any]):
self.ret = ret
self.thread = thread
self.status = Result.Status.CREATED
self.start()
def start(self):
if self.status == Result.Status.CREATED:
self.status = Result.Status.RUNNING
self.thread.start()
def wait(self):
if self.status != Result.Status.DONE:
self.thread.join()
self.status = Result.Status.DONE
def get_statevector(self):
self.wait()
return self.ret['state']
def __repr__(self):
rp = f'Result <{self.status}>'
return rp