473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

cancellable timed loop

I am very new to python and programming in general and am trying to build a loop that can be cancelled when the timer ends or cancelled by a variable that will be set externally. I am testing with my code below and it doesn't want to cancel, like it never re-reads the variable to realize that it is no longer a 1. It seems like I am either really close or way off.

Expand|Select|Wrap|Line Numbers
  1. import threading
  2. scalavar = 1
  3. enable = 1
  4. def disable():
  5.     scalavar=0
  6.     print 'timer stop'
  7. timer = threading.Timer(5,disable)
  8. timer.start()
  9. while (enable == 1):
  10.     if (enable == 1):
  11.         print 'working'
  12.         enable=scalavar
  13.     elif (enable != 1):
  14.         break
  15.  
  16.  
  17. print 'Goodbye'
Aug 14 '10 #1
2 2054
bvdet
2,851 Expert Mod 2GB
Declare scalavar a global variable.

Expand|Select|Wrap|Line Numbers
  1. def disable():
  2.     global scalavar
  3.     scalavar=0
  4.     print 'timer stop'
Aug 14 '10 #2
Thank you sir, that did the trick!
Aug 16 '10 #3

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

Similar topics

11
by: Malcolm Messiter | last post by:
Hello I have a question to while I hope someone has the answer! In order to send several SMS texts from a web site, I need to invoke a new URL with a query string containing the parametres. So...
5
by: Verde | last post by:
I'm using a 3rd party component in an ASP.NET 1.1 Web application. The component has a .Click event that can be fired from the client, with an associated event procedure in the code-behind module....
2
by: William F. Robertson, Jr. | last post by:
Some of my users are receiving an error: Server Error in '/' Application. ---------------------------------------------------------------------------- ---- Request timed out. Description: An...
11
by: www.MessageMazes.com | last post by:
I sometimes get this error after about 60 seconds of "waiting for mazes.com" (but when the page works, it usually loads in less than 12 seconds). > Active Server Pages error 'ASP 0113' > Script...
102
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to...
1
by: Pooja | last post by:
Hi, I am calling a web service to get Latitude and Longitude by sending a zip code. This is happening inside a loop (2000 - 3000 times). After say 80 times, it gives me an error - The operation...
2
by: Thomas Ploch | last post by:
Hello folks, I am having troubles with implementing a timed queue. I am using the 'Queue' module to manage several queues. But I want a timed access, i.e. only 2 fetches per second max. I am...
12
by: owestcot | last post by:
I'm working on a simple video game program that will require timed responses. The easiest example I can think of would be something like: char ans; // answer to question (can't remember the...
1
by: Dracitus | last post by:
i have been trying to set a amount of time a random number has like TextBox6.Text = CStr(Int(Rnd() * 10)) ' This variable will be the loop counter.
3
by: =?Utf-8?B?SnVzdGluIERvaA==?= | last post by:
I am constantly getting the 'Script timed out' error, and would like to see if there is any way I could modify the ASP page. I think I did all I could to improved the performance at the database...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.