473,320 Members | 1,909 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,320 software developers and data experts.

use threading without classes

Hi all. Hi would like to use two threads in a program but all the examples I
found on the net use oop programming that I doesn't love too much. :-)
Can you code me a short example in wich two different functions are executed
at the same time, plz?

Thank you all.
Aug 31 '05 #1
3 3711
Is there any reason why you wouldn't want to do this using the the
threading class? To each his own I suppose. You can try the following
though you'll at least need to use functions:
import time
import thread

def myfunction(string,sleeptime,*args):
while 1:

print string
time.sleep(sleeptime) #sleep for a specified amount of time.

if __name__=="__main__":

thread.start_new_thread(myfunction,("Thread No:1",2))

while 1:pass

Aug 31 '05 #2
billiejoex wrote:
Hi all. Hi would like to use two threads in a program but all the examples I
found on the net use oop programming that I doesn't love too much. :-)
Can you code me a short example in wich two different functions are executed
at the same time, plz?


import time
from threading import Thread

def func1():
print 'first func running'
time.sleep(1)
print 'first func done'

def func2():
print 'second func running'
time.sleep(1)
print 'second func done'

Thread(target=func1).start()
Thread(target=func2).start()

Note that this is still using "OOP programming", and you can't
effectively avoid this in Python without jumping through more hoops than
you're really interested in, but this basically avoids the need to do
OOP things like subclassing.

-Peter
Aug 31 '05 #3
Thank you for your helping.
Aug 31 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
8
by: Mahesh Devjibhai Dhola [MVP] | last post by:
We are building Chat like application using Forms and as a result our programming is becoming complicated to display messages received on different threads in the chat window (due to STA...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
2
by: mattbennett | last post by:
Hi, I'm new to python, and having problems instantiating classes. My main method has a couple of lines like this: debug = False stats_d = {"cpu":,"foo":,"bar":,"baz":} ...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
3
by: daveL | last post by:
I have a large Table to load from Sql2005 i want to load it in a Separate Thead Thread works fine, data gets loaded My question is How to raise a Event When its Completed the Thread Thanks...
9
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.