-
Notifications
You must be signed in to change notification settings - Fork 8
/
QDSpy_multiprocessing.py
104 lines (89 loc) · 2.91 KB
/
QDSpy_multiprocessing.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
QDSpy module - to synchronize QDSpy processes
'Sync'
Class to synchronize states and data (via a pipe) between the GUI process
and the stimulus presenter process
Copyright (c) 2013-2024 Thomas Euler
All rights reserved.
2024-06-11 - Reformatted (using Ruff)
"""
# ---------------------------------------------------------------------
__author__ = "[email protected]"
import time
from multiprocessing import Pipe, Value
# ---------------------------------------------------------------------
# Multiprocessing support
# ---------------------------------------------------------------------
UNDEFINED = 0
PRESENTING = 1
COMPILING = 2
CANCELING = 3
TERMINATING = 4
IDLE = 5
PROBING = 6
StateStr = dict(
[
(UNDEFINED, "Undefined"),
(PRESENTING, "Presenting"),
(COMPILING, "Compiling"),
(CANCELING, "Canceling"),
(TERMINATING, "Terminating"),
(IDLE, "Idle"),
(PROBING, "Probing"),
]
)
class PipeValType:
toCli_log = 0
toCli_displayInfo = 1
toCli_IODevInfo = 2
toCli_TEMP = 3
# ...
toSrv_None = 9
toSrv_fileName = 10
toSrv_changedStage = 11
toSrv_changedLEDs = 12
toSrv_probeParams = 13
toSrv_checkIODev = 14
toSrv_setIODevPins = 15
# ---------------------------------------------------------------------
# Sync class
# ---------------------------------------------------------------------
class Sync:
def __init__(self):
""" Initializing
"""
self.Request = Value("i", IDLE)
self.State = Value("i", UNDEFINED)
self.pipeCli, self.pipeSrv = Pipe()
"""
dx = 64 #912 //6
dy = 128 #1140 //6
self.FrameSize = (dx, dy)
self.Frame = Manager().Array("B", [0]*dx*dy*3)
'''
multiprocessing.sharedctypes.Array(typecode_or_type, size_or_initializer, *args[, lock])
'''
print("class Sync|_init__|len(self.Frame)=", len(self.Frame))
"""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def setStateSafe(self, _newState):
self.State.value = _newState
def setRequestSafe(self, _newReq):
self.Request.value = _newReq
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def waitForState(self, _targetState, _timeout_s=0.0, _updateProc=None):
""" Wait for "mpState" to reach a certain state or for timeout, if given.
Returns True, if stage was reached within the timeout period
"""
timeout = False
t_s = time.time()
while not (self.State.value == _targetState) and not (timeout):
if _updateProc is not None:
_updateProc()
time.sleep(0.05)
if _timeout_s > 0.0:
timeout = (time.time() - t_s) >= _timeout_s
return not (timeout)
# --------------------------------------------------------------------