threading_test.py 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import threading
  2. from binascii import b2a_hex
  3. def main():
  4. num_threads = 10
  5. use_threads = True
  6. if not use_threads:
  7. # Run core code
  8. runShapelyBuilding()
  9. else:
  10. threads = [
  11. threading.Thread(target=runShapelyBuilding, name=str(i), args=(i,))
  12. for i in range(num_threads)
  13. ]
  14. for t in threads:
  15. t.start()
  16. for t in threads:
  17. t.join()
  18. def runShapelyBuilding(num):
  19. print(f"{num}: Running shapely tests on wkb")
  20. import shapely.geos
  21. print(f"{num} GEOS Handle: {shapely.geos.lgeos.geos_handle}")
  22. import shapely.wkb
  23. import shapely.wkt
  24. p = shapely.wkt.loads("POINT (0 0)")
  25. print(f"{num} WKT: {shapely.wkt.dumps(p)}")
  26. wkb = shapely.wkb.dumps(p)
  27. print(f"{num} WKB: {b2a_hex(wkb)}")
  28. for i in range(10):
  29. shapely.wkb.loads(wkb)
  30. print(f"{num} GEOS Handle: {shapely.geos.lgeos.geos_handle}")
  31. print(f"Done {num}")
  32. if __name__ == "__main__":
  33. main()