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

What is wrong with my Python threading?

#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

import threading
import time

def printesc(thrd):
for i in range(10):
time.sleep(1)
print thrd, i

def master():
thd1 = threading.Thread(target=printesc, args=(1,))
thd2 = threading.Thread(target=printesc, args=(2,))
thd1.run()
thd2.run()

master()
Jun 27 '08 #1
5 797
On May 20, 8:19*am, "Chuckk Hubbard" <badmuthahubb...@gmail.com>
wrote:
#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

import threading
import time

def printesc(thrd):
* * for i in range(10):
* * * * time.sleep(1)
* * * * print thrd, i

def master():
* * thd1 = threading.Thread(target=printesc, args=(1,))
* * thd2 = threading.Thread(target=printesc, args=(2,))
* * thd1.run()
* * thd2.run()

master()
You meant 'thd1.start( )' and 'thd2.start( )'.
Jun 27 '08 #2
Chuckk Hubbard wrote:
#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk
Because you should call thread.start().
Diez
Jun 27 '08 #3
En Tue, 20 May 2008 10:28:51 -0300, castironpi <ca********@gmail.com>
escribió:
You meant 'thd1.start( )' and 'thd2.start( )'.
Wow! A message with a high S/N ratio coming from you!
And it's not the first I've seen - whatever pills you're taking, they're
good for you...

--
Gabriel Genellina

Jun 27 '08 #4
On Tue, May 20, 2008 at 8:24 PM, Gabriel Genellina
<ga*******@yahoo.com.arwrote:
En Tue, 20 May 2008 10:28:51 -0300, castironpi <ca********@gmail.com>
escribió:
>You meant 'thd1.start( )' and 'thd2.start( )'.

Wow! A message with a high S/N ratio coming from you!
And it's not the first I've seen - whatever pills you're taking, they're
good for you...
This is why I shouldn't be so eager adding people to the killfile.
--
Eduardo de Oliveira Padoan
http://www.advogato.org/person/eopadoan/
http://twitter.com/edcrypt
Bookmarks: http://del.icio.us/edcrypt
Jun 27 '08 #5
On Tue, May 20, 2008 at 4:28 PM, castironpi <ca********@gmail.comwrote:
On May 20, 8:19 am, "Chuckk Hubbard" <badmuthahubb...@gmail.com>
wrote:
>#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

import threading
import time

def printesc(thrd):
for i in range(10):
time.sleep(1)
print thrd, i

def master():
thd1 = threading.Thread(target=printesc, args=(1,))
thd2 = threading.Thread(target=printesc, args=(2,))
thd1.run()
thd2.run()

master()

You meant 'thd1.start( )' and 'thd2.start( )'.
So I did. I was mixing what I read of thread and threading. I'll
never wander beyond my Python module reference html folder again.
Thanks for your help.

-Chuckk

--
http://www.badmuthahubbard.com
Jun 27 '08 #6

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

Similar topics

38
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.1 (final). Python 2.3.1 is a pure bug fix release of Python 2.3, released in...
7
by: kanzen | last post by:
I keep telling my friends that Python rocks. Now it's time to put my money where my mouth is. I'm about to start writing a server for a phone based game. It needs to handle simlpe requests from...
3
by: David Harrison | last post by:
I am working on an application on Mac OS X that calls out to python via PyImport_ImportModule(). I find that if the imported module creates and starts a python thread, the thread seems to be...
1
by: Qiangning Hong | last post by:
I decide to seperate my data collection routine from my data analysis and storage program to a seperate process, so I try to use the new subprocess model in Python 2.4. The main program spawns...
13
by: Yannick | last post by:
Hi, I would like to program a small game in Python, kind of like robocode (http://robocode.sourceforge.net/). Problem is that I would have to share the CPU between all the robots, and thus...
5
by: momobear | last post by:
I feel really puzzled about fellowing code, please help me finger out what problem here. import threading class workingthread(threading.Thread): def __init__(self): self.quitEvent =...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42) Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86) RFE : 262 open...
0
by: Ling | last post by:
I am using boost.python to wrap C++ function which includes directmusic libraries to simply play the midi, but lots of linkage errors "error LNK2001: unresolved external symbol". I wonder if it is...
2
by: Matthew Wilson | last post by:
In this code, I tried to kill my thread object by setting a variable on it to False. Inside the run method of my thread object, it checks a different variable. I've already rewritten this...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...

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.