-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrift.py
More file actions
executable file
·30 lines (22 loc) · 830 Bytes
/
thrift.py
File metadata and controls
executable file
·30 lines (22 loc) · 830 Bytes
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
import thriftpy2
from thriftpy2.rpc import make_server
import time
# Load the Timestamp thrift definition
timestamp_thrift = thriftpy2.load("timestamp.thrift", module_name="timestamp_thrift")
Timestamp = timestamp_thrift.TimestampService
# Define the handler class
class TimestampHandler:
# Method to get the current system timestamp
def getCurrentTimestamp(self):
return int(time.time())
# Method to echo the provided timestamp
def echoTimestamp(self, timestamp):
return timestamp
if __name__ == "__main__":
# Instantiate the handler
handler = TimestampHandler()
# Create a server with the handler
server = make_server(Timestamp, handler, '127.0.0.1', 10000)
# Start serving requests
print("Thrift server started. Listening on port 10000...")
server.serve()