Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This problem has no solution if you strictly want this script "to be called from another program. by issuing 'python script.py' on command line". If you want to do the "heavy import" only once, you have to start python script only once. Think about starting a daemon, which will start once and then process calls from other program. This way all initialization has to be done only one time and next calls will be fast. And if you split your python code into two parts (first part for daemon, second for daemon client), you'll be able to call 'python client.py' from another program, but actual computation will be performed by daemon, which is started just one time.</p> <p>As example:</p> <p><strong>daemon.py</strong></p> <pre><code>import socket #import arcpy def actual_work(): #val = arcpy.GetCellValue_management("D:\dem-merged\lidar_wsg84", "-95.090174910630012 29.973962146120652", "") #return str(val) return 'dummy_reply' def main(): sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) try: sock.bind( ('127.0.0.1', 6666) ) while True: data, addr = sock.recvfrom( 4096 ) reply = actual_work() sock.sendto(reply, addr) except KeyboardInterrupt: pass finally: sock.close() if __name__ == '__main__': main() </code></pre> <p><strong>client.py</strong></p> <pre><code>import socket import sys def main(): sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) sock.settimeout(1) try: sock.sendto('', ('127.0.0.1', 6666)) reply, _ = sock.recvfrom(4096) print reply except socket.timeout: sys.exit(1) finally: sock.close() if __name__ == '__main__': main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload