pydicom / pynetdicom

A Python implementation of the DICOM networking protocol

Home Page:https://pydicom.github.io/pynetdicom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SCP closes immediately after start_server

Elepert opened this issue · comments

Pynetdicom version: 2.0.2
Python: 3.9

I'm trying to run a simple SCP server as follows, but the server stops immediately after being created:

from pynetdicom import AE, StoragePresentationContexts, DEFAULT_TRANSFER_SYNTAXES, evt

ae = AE()
transfer_syntaxes = DEFAULT_TRANSFER_SYNTAXES + [pydicom.uid.JPEGLossless, pydicom.uid.JPEG2000Lossless]
for context in StoragePresentationContexts:
    ae.add_supported_context(context.abstract_syntax, transfer_syntaxes)

def handle_store(event):
    """Handle a C-STORE request event."""
    pass

handlers = [(evt.EVT_C_STORE, handle_store)]

# Start listening for incoming association requests
ae.start_server(("", 2007), evt_handlers=handlers, block=False)

To my knowledge this is code that closely resembles the tutorial here: https://pydicom.github.io/pynetdicom/stable/tutorials/create_scp.html

When I run this in the command line, the server does not remain running, the file finishes executing immediately. I'm forced to add a

while True:
     time.sleep(1)

after the start_server to keep the connection alive. What am I missing here?

You need to start it with block=True, otherwise it's non blocking (as the option suggests).

@Elepert - did this answer your question?

Yes! I had tried that originally and it didn't work, but after your comment I tried again and realized some outside code was forcing the execution to stop. Thanks!