Python - THREADING SERVIDOR WEB

 
Vista:

THREADING SERVIDOR WEB

Publicado por Antonio FLORES (2 intervenciones) el 07/06/2017 16:19:45
Hola soy nuevo en PYTHON pero necesito dar la estructura de THREADING a un servidor web que sirve para monitorear un led on/off

He intentado integrar a mi programa el modo THREADING pero me marca errores y no entiendo de donde provienen

El programa es el siguiente
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
#!/usr/bin/env python
 
import web
 
import RPi.GPIO as GPIO
 
from web import form
 
import time
 
import os
 
import socket
 
import threading
 
 
 
# definit GPIO4 en sortie 
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setup(4, GPIO.OUT)
 
 
# definit la page de nom index pour le site web 
 
urls = ('/', 'index')
 
dossier_web = web.template.render('templates')
 
app = web.application(urls, globals())
 
 
# definit les boutons a afficher 
 
ma_forme = form.Form(
 
form.Button("btn", id = "btnon", value = "on", html = "On", class_ = "bouton_on"),
 
form.Button("btn", id = "btnoff", value = "off", html = "Off", class_ = "bouton_off")
 
 
 
class task_index(threading.Thread)
 
 
def __init__(self, nom = ''):
 
threading.Thread.__init__(self)
 
self.nom = nom
 
self.Terminated = False
 
def GET(self):
 
        forme = ma_forme()
 
        return dossier_web.index(forme, "Raspberry Pi control GPIO4")
 
 
 
    # utilise quand une forme web est soumise 
 
    def POST(self):
 
        userdata = web.input()
 
        if userdata.btn == "on":
 
                GPIO.output(4, True)
 
        if userdata.btn == "off":
 
               GPIO.output(4, False)
 
        # recharge la page web 
 
        raise web.seeother('/'
 
 
def run(self):
 
          global app
 
           if __name__ == '__main__':
 
                 app.run()
 
 
def stop(lf):
 
self.Terminated = True
 
 
 
# Lancement threads
 
t1 = task_index("task_index")
 
t1.start()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder