Need a little help with this code

50 views
Skip to first unread message

Bruno Brusantin

unread,
Mar 2, 2015, 7:42:46 AM3/2/15
to autob...@googlegroups.com
Hello,

i`m trying to use a IR receiver and pylirc to pass comands from my TV remote over wifi using WAMP


blocking = 0
if(pylirc.init("pylirc", "./conf", blocking)):

    code
= {"config" : ""}
   
while(code["config"] != "quit"):
       
# Read next code
        s
= pylirc.nextcode(1)

       
# Loop as long as there are more on the queue
       
# (dont want to wait a second if the user pressed many buttons...)
       
while(s):
           
for (code) in s:
               
#print "Command: %s, Repeat: %d" % (code["config"], code["repeat"])

               
event = code["config"]
               
if (event == "test"):
                   
self.publish(server_events, event,hostname)
                   
print (server_events, code["config"], hostname)

               
if (event == "quit"):
                    pylirc
.exit()

           
if(not blocking):
                s
= pylirc.nextcode(1)
           
else:
                s
= []

   
# Clean up lirc
    pylirc
.exit()

the code kinda works.
i pass the "test" command
it runs the IF, prints the message below the self.publish

but the self.publish only runs after i pass the quit comand to end the loop. I can pass many commands, but they stay in queue and only run after the loop ends.

what am i doing wrong ?

Tobias Oberstein

unread,
Mar 2, 2015, 10:12:29 AM3/2/15
to autob...@googlegroups.com
Hi Bruno,

I don't know about pylirc - but if it is a blocking library, you can't
use (blocking) calls into pylirc, as this will block the whole event loop.

If you need to do blocking calls, those need to live on threads
(deferToThread etc).

/Tobias
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/db29c3a9-0680-46f9-aa15-0429c08fa924%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/db29c3a9-0680-46f9-aa15-0429c08fa924%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages