File: 13_life_cycle.py

package info (click to toggle)
python-trame 3.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (58 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (2)
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
import json

from trame.app import get_server

# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
ctrl = server.controller

# -----------------------------------------------------------------------------
# Life Cycle events
# -----------------------------------------------------------------------------


def server_ready(**state):
    print("on_server_ready")
    print("  => current state:")
    print(json.dumps(state, indent=2))
    print("-" * 60)


def client_connected():
    print("on_client_connected")


def client_unmounted():
    print("on_client_unmounted")


def client_exited():
    print("on_client_exited")


def server_exited(**state):
    print("on_server_exited")
    print("  => current state:")
    print(json.dumps(state, indent=2))
    print("-" * 60)


# -----------------------------------------------------------------------------
# Life Cycle registration
# -----------------------------------------------------------------------------

ctrl.on_server_ready.add(server_ready)
ctrl.on_client_connected.add(client_connected)
ctrl.on_client_unmounted.add(client_unmounted)
ctrl.on_client_exited.add(client_exited)
ctrl.on_server_exited.add(server_exited)

# -----------------------------------------------------------------------------
# start server
# -----------------------------------------------------------------------------

if __name__ == "__main__":
    server.start()