Threads: Issue and suggestion required

S

Sandeep Arya

Hello

I am developing an application using PyQT.


My application scenario is:: "At any instance one socket is open in my
application. Now if user wants to execute some command on another machine/IP
address, then i need to make another socket and execute task."

My query is. Is this possible that my main thread and my newly born thread
will execute their task simultaneously/parallel. (I read that Python
interpretor allows only one thread execution at a time. Using its global
lock. And switch among active thread based on time set by setSwitchTime()
function.. Is this correct?)

I just wannn know what is lifetime of thread. As I was planning to implement
one function such that:

1.0 function starts
2.0 create socket
3.0 Open socket
4.0 Do whatever task to do
5.0 Close socket
6.0 Function ends

I wanna know that if i assign such above mentioned function to thread::run
then will the thread die after step 6.0 above i.e. function ends.


Suggest me.

Thanking You

Sandeep

_________________________________________________________________
Get faster and relevant results. http://search.msn.co.in Switch to the
smarter search!
 
P

Peter Hansen

Sandeep said:
My query is. Is this possible that my main thread and my newly born
thread will execute their task simultaneously/parallel. (I read that
Python interpretor allows only one thread execution at a time. Using its
global lock. And switch among active thread based on time set by
setSwitchTime() function.. Is this correct?)

Where did you see something about a setSwitchTime() function?

Anyway, the statement about Python allowing "only one thread execution
at a time" is wrong (allowing for the possibility of misunderstanding
given that it's grammatically incorrect, so you might have meant
something other than what I understand it as). By definition, threads
simulate "parallel units of execution", so certainly threads (in almost
any system) appear to execute simultaneously. In practice, of course,
if you have only a single CPU then only one thing at a time can be
happening (things like interrupts aside), and in an interpreter like
Python's the same thing applies at a higher level: only one "bytecode"
instruction at a time can be executing. Nevertheless, threads in Python
certainly "appear" to execute in parallel, whether you have two or ten,
and the details are generally transparent at the level you are
interested in...
I just wannn know what is lifetime of thread.

A threads runs until it ends...
As I was planning to
implement one function such that:

1.0 function starts
2.0 create socket
3.0 Open socket
4.0 Do whatever task to do
5.0 Close socket
6.0 Function ends

I wanna know that if i assign such above mentioned function to
thread::run then will the thread die after step 6.0 above i.e. function
ends.

Basically that is correct. Anyway, threads in Python are trivial to
play with, even at the interactive prompt, so why not just try them out
and see how things go?

-Peter
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top