Threading - will threads run in parallel?

S

SolaFide

I have 2 threads that I want to run at the same time: for instance:

from threading import Thread

class test(Thread):
def run(self):
while True:
get(asdf)

class test2(Thread):
def run(self):
while True:
get(jkl)
ack=test()
jkl=test2()
ack.start()
jkl.start()

(get() is a function which waits for a ping on a specific port, thus
stopping the program for a while.)

Will these run together, or do I have to find some other way of running
in parallel?

Also, is it possible to split off a program for the terminal that
started it? As in I type in python test.py and test.py runs in the
background and lets me do other things in that terminal?
 
I

Ido Yehieli

Also, is it possible to split off a program for the terminal that
try:
python test.py &
 
R

Rene Pijlman

SolaFide:
(get() is a function which waits for a ping on a specific port, thus
stopping the program for a while.)

Will these run together,

Thread 2 can run while thread 1 is blocked for I/O and v.v.
Also, is it possible to split off a program for the terminal that
started it? As in I type in python test.py and test.py runs in the
background and lets me do other things in that terminal?

Platform? Shell?
 
S

SolaFide

Thanks!

The problem is on Windows: when I run c:\python24\myprogram.py, it has
a command window open up. If I close it, the program ends. So I want it
to run without opening that window.
 
J

Jarek Zgoda

SolaFide napisa³(a):
The problem is on Windows: when I run c:\python24\myprogram.py, it has
a command window open up. If I close it, the program ends. So I want it
to run without opening that window.

Give it .pyw extension or start using pythonw.exe instead of python.exe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top