Skip to content

Server shutdown conflict with Numba #1976

Open
@Giofraant

Description

@Giofraant

Before submitting the issue

  • I have checked for Compatibility issues
  • I have searched among the existing issues
  • I am using a Python virtual environment

Description of the bug

I am currently trying to do numba accelerated post processing on data, acquired from an .rst file, by using the Ansys DPF core library. When I try to shut down the server to enable numba, it seems that the server still exists, which prevents numba from performing, resulting in the following error:

Traceback (most recent call last):
  File "User\AppData\Roaming\Python\Python311\site-packages\ansys\dpf\core\dpf_operator.py", line 732, in __del__
AttributeError: 'NoneType' object has no attribute 'warn'
Exception ignored in: <function Operator.__del__ at 0x0000027DB55F5C60>

Followed by many identical errors.

I'm unsure how to fix this or if I'm simply on the wrong track and what I have to do to fix this issue.

Steps To Reproduce

# to measure speeds of mockup calculations
import time 

import numpy as np
import ansys.dpf.core as dpf

from numba import njit
from pathlib import Path

SERVERCONFIG = dpf.ServerConfig(protocol=dpf.server.CommunicationProtocols.InProcess, legacy=False)
SERVER = dpf.start_local_server(
    config=SERVERCONFIG,
    as_global=False,
    load_operators=False,
    use_docker_by_default=False,
    use_pypim_by_default=False
    )

my_path = Path(r"example_bracket.rst")
my_source = dpf.DataSources(my_path, server= SERVER)

my_scope = dpf.Model(my_source, server= SERVER)
my_result = my_scope.results.stress

my_array = np.copy(my_result.eval()[0].data)

del(my_source)

# see if server exists
print(dpf.server.available_servers())

# kill it
dpf.server.shutdown_all_session_servers()
dpf.server.shutdown_global_server()

# try again
print(dpf.server.available_servers())

# The following functions are random, computational heavy calculations to see performance results

def arraydicolous(arr: np.array, anumber: int):
    num = np.sum(arr)
    for i in range(anumber+1):
        num += np.sum(arr * i)
    return num

@njit
def anumbadicolous(arr: np.array, anumber: int):
    num = np.sum(arr)
    for i in range(anumber+1):
        num += np.sum(arr * i)
    return num

# measure both functions' time.
test1_t1 = time.time()
print(arraydicolous(my_array, 200000))
test1_t2 = time.time()

print(test1_t2-test1_t1)

test2_t1 = time.time()
print(anumbadicolous(my_array, 200000))
test2_t2 = time.time()

print(test2_t2-test2_t1)

Which Operating System causes the issue?

Windows

Which DPF/Ansys version are you using?

Ansys 2024 R2

Which Python version causes the issue?

3.11

Installed packages

ansys-dpf-core==0.13.3
numba @ file:///C:/b/abs_51yyu3qucu/croot/numba_1720540987599/work
numpy==1.26.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions