1

This is my Python Code :

import threading
import time
import MySQLdb
import sys
conn=MySQLdb.connect (host = "localhost",
 user = "root",
 passwd = "",
 db = "profiles_sheduleit")
cur = conn.cursor()
def activation(): 
 while True:
 time.sleep(1)
 print time.time()
t = threading.Thread(name='activation', target=activation)
t.start()

I am calling this page from my php page by:

$result = exec("c:/python27/python f:/python/hello.py");

I have one few buttons in php when this button is clicked a new thread should me created and that thread should run for 10 seconds.

but when i click the button m not able to click another button because python script goes into sleep mode thanx

Otto Allmendinger
28.5k7 gold badges71 silver badges79 bronze badges
asked Jul 11, 2012 at 10:26
1
  • 6
    activation function, has an infinite loop Commented Jul 11, 2012 at 10:31

1 Answer 1

3

your python script never terminates because your thread runs for ever due to your while True: statement. This causes the exec function to wait indefinitely. All PHP's exec like functions are blocking, meaning that they'll wait until the process they call has returned.

Look into something like gearman, if you want to create a work queue. It's essentially a job server that allows for async execution.

answered Jul 11, 2012 at 10:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.