Forum

Author Topic: Network Task RunScript NumPy  (Read 2558 times)

SamT

  • Newbie
  • *
  • Posts: 39
    • View Profile
Network Task RunScript NumPy
« on: April 06, 2020, 03:41:27 AM »
Hey Everyone,

Hoping somebody may have a solution to an error that I am facing.

I want to use numpy in an external script (test_numpy.py) as a network task called from another script (network_process.py)

The script runs successfully when launched as a task through the GUI but blocks indefinitely when called from python.

Stopping the server causes the script to run successfully. Removing "import numpy" also succeeds.

I have attached both scripts.

Metashape version is 1.6.2




SamT

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Network Task RunScript NumPy
« Reply #1 on: April 28, 2020, 03:58:11 AM »
Thinking that this it GIL related. See https://lists.gt.net/python/dev/1406603

Unfortunately this is stopping me from using any libraries that depend on numpy like Tensorflow.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Network Task RunScript NumPy
« Reply #2 on: April 28, 2020, 06:27:15 PM »
Hello Sam,

Can you please check if the following modification in your script solves the problem.

Instead of line 12: n_t.frames.append((chunk.key, 0)) put the following:

Code: [Select]
if t.target == Metashape.Tasks.ChunkTarget:
        n_t.chunks.append(chunk.key)
if t.target == Metashape.Tasks.FrameTarget:
        n_t.frames.append((chunk.key, 0))
Best regards,
Alexey Pasumansky,
Agisoft LLC

SamT

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Network Task RunScript NumPy
« Reply #3 on: April 29, 2020, 02:14:58 AM »
Hi Alexey,

Issue persists unfortunately.

This runs fine:
Code: [Select]
# import numpy

print('RunScript complete')

This blocks indefinitely:
Code: [Select]
import numpy

print('RunScript complete')

SamT

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Network Task RunScript NumPy
« Reply #4 on: April 29, 2020, 04:25:49 AM »
I should also mention that this runs:
Code: [Select]
import requests

print('RunScript complete')

However it throws this Exception.
Code: [Select]
2020-04-29 11:23:43 Exception ignored in: <module 'threading' from 'C:\\Program Files\\Agisoft\\Metashape Pro\\python\\lib\\threading.py'>
2020-04-29 11:23:43 Traceback (most recent call last):
2020-04-29 11:23:43   File "C:\Program Files\Agisoft\Metashape Pro\python\lib\threading.py", line 1283, in _shutdown
2020-04-29 11:23:43     assert tlock.locked()
2020-04-29 11:23:43 AssertionError:


So I know that I can use libs I have installed with pip

SamT

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Network Task RunScript NumPy
« Reply #5 on: May 11, 2020, 12:58:10 AM »
Hi Alexey,

Did you manage to replicate this behavior or do you think it is just my system?

I have attached a minimum example.

« Last Edit: May 11, 2020, 07:20:45 AM by SamT »