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.
Regards,
Ashish Vyas
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?
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 .
I personally use subprocess. Once you launch via subprocess you can
wait or not.
p = subprocess.Popen(...)
p.wait() #or not.
See subprocess docs.
> 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
...
> 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.