Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to execute a script from another script and other script does not do busy wait.

0 views
Skip to first unread message

Rajat

unread,
Jan 7, 2010, 4:12:23 AM1/7/10
to
I want to run a python script( aka script2) from another python script
(aka script1). While script1 executes script2 it waits for script2 to
complete and in doing so it also does some other useful work.(does not
do a busy wait).

My intention is to update a third party through script1 that script2
is going to take longer.

Please suggest how should I go about implementing it.

I'm currently executing it as:

import main from script2
ret_code = main()
return ret_code

which surely is not going to achieve me what I intend.


Thanks,
Rajat.

VYAS ASHISH M-NTB837

unread,
Jan 7, 2010, 4:21:20 AM1/7/10
to Rajat, pytho...@python.org

Use threads

Regards,
Ashish Vyas

Rajat

unread,
Jan 7, 2010, 6:19:19 AM1/7/10
to
On Jan 7, 2:21 pm, "VYAS ASHISH M-NTB837" <ashish.v...@motorola.com>
wrote:

> Use threads
>
> Regards,
> Ashish Vyas
>
>
>
> -----Original Message-----
> From: python-list-bounces+ntb837=motorola....@python.org
>
> [mailto:python-list-bounces+ntb837=motorola....@python.org] On Behalf Of

> Rajat
> Sent: Thursday, January 07, 2010 2:42 PM
> To: python-l...@python.org

> Subject: How to execute a script from another script and other script
> does notdo busy wait.
>
> I want to run a python script( aka script2) from another python script
> (aka script1). While script1 executes script2 it waits for script2 to
> complete and in doing so it also does some other useful work.(does not
> do a busy wait).
>
> My intention is to update a third party through script1 that script2 is
> going to take longer.- Hide quoted text -
>
> - Show quoted text -

Thanks Ashish.

I've single CPU machine. I've a feeling that the thread created, which
would run script2, would eat up all of the CPU if I do not use sleep()
in script2.

That way, script1 would still be waiting for script2 to finish. Thus,
my program is no way different from the sample program I posted
earlier.

Is there any other way out?

VYAS ASHISH M-NTB837

unread,
Jan 7, 2010, 6:33:43 AM1/7/10
to pytho...@python.org
Did you try?

Jorgen Grahn

unread,
Jan 7, 2010, 11:18:32 AM1/7/10
to
On Thu, 2010-01-07, Rajat wrote:
> I want to run a python script( aka script2) from another python script
> (aka script1). While script1 executes script2 it waits for script2 to
> complete and in doing so it also does some other useful work.(does not
> do a busy wait).
>
> My intention is to update a third party through script1 that script2
> is going to take longer.

I do not understand that sentence.
What are you trying to do, more exactly? The best solution can be
threads, os.popen, os.system or something different -- depending on
the details of what you want to do.

> Please suggest how should I go about implementing it.
>
> I'm currently executing it as:
>
> import main from script2
> ret_code = main()
> return ret_code
>
> which surely is not going to achieve me what I intend.
>
>
> Thanks,
> Rajat.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

danmc...@yahoo.com

unread,
Jan 7, 2010, 2:48:45 PM1/7/10
to

I personally use subprocess. Once you launch via subprocess you can
wait or not.

p = subprocess.Popen(...)
p.wait() #or not.

See subprocess docs.

Jan Kaliszewski

unread,
Jan 7, 2010, 3:18:27 PM1/7/10
to pytho...@python.org
Rajat <rajat....@gmail.com> wrote:

> I've single CPU machine. I've a feeling that the thread created, which
> would run script2, would eat up all of the CPU if I do not use sleep()
> in script2.

> That way, script1 would still be waiting for script2 to finish.

Single CPU is not a problem for threads (in fact it's even better).
It'll work. Try it.

Another possibility is to run script2 in a separate process (e.g. using
subprocess module).

Cheers,
*j

Jorgen Grahn

unread,
Jan 8, 2010, 9:05:52 AM1/8/10
to
On Thu, 2010-01-07, danmc...@yahoo.com wrote:
> On Jan 7, 9:18�am, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
>> On Thu, 2010-01-07, Rajat wrote:
>> > I want to run a python script( aka script2) from another python script
>> > (aka script1). While script1 executes script2 it waits for script2 to
>> > complete and in doing so it also does some other useful work.(does not
>> > do a busy wait).
>>
>> > My intention is to update a third party through script1 that script2
>> > is going to take longer.
>>
>> I do not understand that sentence.
>> What are you trying to do, more exactly? �The best solution can be
>> threads, os.popen, os.system or something different -- depending on
>> the details of what you want to do.

...

> I personally use subprocess. Once you launch via subprocess you can
> wait or not.
>
> p = subprocess.Popen(...)
> p.wait() #or not.
>
> See subprocess docs.

Yes, that was included in "or something different" above. I have never
used it myself, since I've needed to be compatible with Python < 2.4.

Still, we need to know what he tries to do.

0 new messages