[Tutor] Wait

dman dman@dman.ddts.net
Thu, 30 May 2002 19:26:01 -0500


--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, May 30, 2002 at 05:17:01PM +0000, Terje Johan Abrahamsen wrote:
| I have written a program that does 4 processes. 1) Find an amount/policy =
in=20
| Excel. 2) Find the same policy in an AS/400 display. 3) Formats the amoun=
t=20
| 4) Writes the amount into the AS/400.
|=20
| However, the problem is that the python program is way faster than the=20
| AS/400 display. So, when the AS/400 is finished, the Python is several=20
| steps ahead. How can I get it to wait until it is done?

To determine this, you need to determine how you can know it is done.

How do you connect to the AS/400?  Are you using a plain old socket or
are you using the telnetlib module?  What will the AS/400 display
differently when it is done?

If you have access to the socket itself, the basic process will be
like this :
    (developer tasks)
    o   determine what properties of the input stream are indicative
        of the mainframe's state (completed, not completed)

    (program tasks)
    o   use select() to asynchronously wait for data from the socket
        (if you can't do this, eg using windows or telnetlib, use a
        busy-wait loop with a small sleep() time in it)

    o   when data arrives via the socket, inspect it for signals that
        the mainframe is ready for the next step

    o   repeat until the mainframe is ready

    o   error checking (throughout all steps)

If you're using telnetlib, then the proces is the same except you
won't be able to use select() on the socket.

| I am currently using the sys.sleep() function. But, to add a 2
| second break everywhere makes it very slow. Especially since most of
| the time 0.2 second break would probably be enough, but in special
| occations it takes longer. And, if you multiply by about 50000
| policies, and about 10 sleeps for each policy to be on the safe
| side, everything takes very long...

You're right -- arbitrarily sleeping is a performance drag, and a
reliability nightmare.  It might work now, but what if something
(somewhere) ever changes?  The timing might need to be refigured.
It is always better to identify some (asynchronous if possible)
condition that can be checked rather than simply waiting and hoping
for the best.

HTH,
-D

--=20

Whoever gives heed to instruction prospers,
and blessed is he who trusts in the Lord.
        Proverbs 16:20
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--n8g4imXOkfNTN/H1
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjz2wxgACgkQO8l8XBKTpRTWAgCggOs6QdTPUXC5h+N/hPbqb8hG
QHMAoLbFJGB9UL7TkwRloMae8kX18DAY
=ugga
-----END PGP SIGNATURE-----

--n8g4imXOkfNTN/H1--