473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

raw_input stops thread?

1 New Member
Hello, im going out of my mind trying to solve this, im new at python and trying to code an alarm system with a raspberry pi.

the alarm threads stops waiting for alarm2 threads raw_input, how can i solve this? Thanks in advance

code below:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. from threading import Thread
  3. from pyrowl import Pyrowl
  4. from datetime import datetime
  5. from espeak import espeak
  6. import piface.pfio as pfio
  7. import subprocess
  8. armed=0
  9. p=None
  10. pfio.init()
  11. def main2(keys):
  12.     global p
  13.     global res
  14.     global cmess
  15.     global armed
  16.     pkey = None
  17.  
  18.     p = Pyrowl()
  19.     if os.path.isfile("myproviderkey"):
  20.         pkey = open("myproviderkey",'r').readline().strip()
  21.         p.providerkey(pkey)
  22.  
  23.     p.addkey(keys)
  24.  
  25.  
  26.  
  27. if __name__ == "__main2__":
  28.     if os.path.isfile('myapikey'):
  29.         keys = filter(None,
  30.                       open("myapikey",'r').read().split("\n")
  31.                       )
  32.  
  33.         main2(keys)
  34.  
  35.  
  36.  
  37.  
  38. def alarm1():
  39.     global armed
  40.     print "Thread running"
  41.     #time.sleep(5)
  42.     while True:        
  43.         if armed==1:
  44.             #while True:
  45.                 #time.sleep(1)
  46.                 print "Alarm active"
  47.                 t2=datetime.now().strftime("%c")
  48.                 if pfio.digital_read(1)==1:
  49.                     print "Alarm! Groventre door open %s"%t2
  50.                 continue
  51.         else:
  52.             print "inactive"
  53.             time.sleep(1)
  54.             continue
  55.  
  56.  
  57. def alarm2():
  58.     global armed
  59.     x=0
  60.     textarm='"10 sekunder"'
  61.     cards=["0008669047","0001479506"]
  62.     print "Starting up...Disarmed\n"
  63.     #while True:
  64.     print "Waiting for card:\n"
  65.     data=raw_input()
  66.     if data in cards :
  67.                 print "Valid card!"
  68.                 if armed==0:
  69.                     #espeak.synth("Card ok, armed in ten seconds")
  70.                     #subprocess.call('espeak -s 110 -vsv ' +textarm, shell=True)
  71.                     time.sleep(5)
  72.                     armed=1
  73.                     time.sleep(2)
  74.                     print "Armed\n"                                  
  75.                     #continue
  76.                 if armed==1:
  77.                     armed=0
  78.                     time.sleep(2)
  79.                     print "Disarmed\n"
  80.  
  81.                     #t.join()                    
  82.                     #continue
  83.  
  84.  
  85. def main():
  86.     #armed=0
  87.     global armed
  88.     t=Thread(target=alarm1)
  89.     t.setDaemon(True)
  90.     t.start()
  91.     t2=Thread(target=alarm2)
  92.     t2.start()
  93.  
  94.  
  95.  
  96. if __name__=='__main__':
  97.     main()
Feb 16 '13 #1
1 2935
dwblas
626 Recognized Expert Contributor
alarm2 only asks for input once and then exits. It might also be a problem with the use of global armed. I use multiprocessing, not threading, but the threads may not communicate so changing something in one thread is not recognized in the other. It retains the value first passed. See Signaling Between Threads on Doug Hellmann's site as a place to start.
Feb 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1558
by: Matt Rapoport | last post by:
I'm running an NT service with a thread. The thread performs a calculation every so often and appends the number to a text file. Every so often the thread just stops - or so it seems. The text...
9
2392
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while True: do_updates() time.sleep(600)
2
7224
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
0
1810
by: dale | last post by:
Python newbie disclaimer on I am running an app with Tkinter screen in one thread and command-line input in another thread using raw_input(). First question - is this legal, should it run...
3
6392
by: Jorge Louis de Castro | last post by:
Hi, Could anyone tell me whether I can find a non blocking alternative to raw_input that works on windows? Is there not a python way of achieving this? Can I find it somewhere in the...
6
23707
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
9
3050
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
2
1062
by: Gary Wessle | last post by:
the output of this code below is not what one would expect, it outputs all kind of numbers and it never stops, I want to ask the user for a number and then print out the multiplication table up to...
5
1536
by: Galen Somerville | last post by:
Tooo many examples. I'm confused. VB6 ActiveX.dll with no windows or controls. Interfaces with a device that returns an x size byte array every x milliseconds for x counts. Sends a message to...
7
2025
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.