forked from PanDAWMS/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PilotYamplServer.py
52 lines (40 loc) · 1.47 KB
/
PilotYamplServer.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
import yampl
import signal
from pUtil import tolog
class PilotYamplServer(object):
""" Yampl server used to send yampl messages from runEvent to AthenaMP """
def __init__(self, name='PilotYamplServer', socketname='EventService_EventRanges', context='local'):
""" Constructor, setting initial variables """
self.srv = None
self.receivedMessage = ""
self.sendMessage = ""
# Default signals
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Create the server socket
try:
self.srv = yampl.ServerSocket(socketname, context)
except Exception, e:
tolog("!!WARNING!!2222!! Could not create Yampl server socket")
else:
tolog("Created a Yampl server socket")
def alive(self):
""" Is the server alive? """
if self.srv:
return True
else:
return False
def send(self, message):
""" Send a yampl message """
if self.alive():
self.srv.send_raw(message)
else:
tolog("!!WARNING!!2221!! Yampl server not available (not created) - cannot send Yampl message")
def receive(self):
""" Receive a yampl message """
if self.alive():
size, buf = self.srv.try_recv_raw()
else:
tolog("!!WARNING!!2221!! Yampl server not available (not created) - cannot receive any Yampl messages")
buf = ""
size = 0
return size, buf