External program with Julia (instead of Python); almost works

17 views
Skip to first unread message

H J

unread,
Nov 20, 2025, 5:27:52 PM (9 days ago) Nov 20
to JaamSim Users Discussion Group
I'm almost successful in running the External_Program example with a Julia `server.jl` script instead of Python `server.py` script. The only problem is that it only reads one request (i.e. first Entitity) and then halts ... I've tried two Julia versions reading from `srtdin`, neither works.

PFA the model cfg file and both server.jl script:
- The `server_req.txt` file is the logged output from the Julia run.
- The original `server.py` file is attached for documentation purposes.

 Someone any idea?

Thanks, Henk
server2.jl
ExternalProgramServer Example - Julia.cfg
server.py
server.jl
server_req.txt

H J

unread,
Nov 21, 2025, 9:49:27 AM (9 days ago) Nov 21
to JaamSim Users Discussion Group
Some additional info:

Whilst debugging a JaamSim run with Julia external program, the crash happens in `EventManager.java` at below location (first line):
```
// If the next event is at the current tick, execute it
if (nextNode.schedTick == currentTick.get()) {          // <= Crash happens here.
// Remove the event from the future events
Event nextEvent = nextNode.head;
ProcessTarget nextTarget = nextEvent.target;
if (trcListener != null) {
disableSchedule();
trcListener.traceEvent(nextNode.schedTick, nextNode.priority, nextTarget);
enableSchedule();
}
```
The java debugger produces this msg:
```
...
ExternalProgramServer1:
Stream closed
Stack trace:
com.jaamsim.basicsim.Entity.error(Entity.java:1092)
com.jaamsim.BasicObjects.ExternalProgramServer.addEntity(ExternalProgramServer.java:226)
com.jaamsim.ProcessFlow.LinkedDevice.sendToNextComponent(LinkedDevice.java:138)
com.jaamsim.ProcessFlow.EntityConveyor.processStep(EntityConveyor.java:336)
com.jaamsim.ProcessFlow.Device.endStep(Device.java:238)
com.jaamsim.ProcessFlow.Device$EndStepTarget.process(Device.java:217)
com.jaamsim.events.EventManager.executeTarget(EventManager.java:179)
com.jaamsim.events.EventManager.execute(EventManager.java:273)
com.jaamsim.events.Process.run(Process.java:98)

Exception in thread "processthread-1" java.lang.NullPointerException: Cannot read field "proc" because the return value of "java.util.concurrent.atomic.AtomicReference.get()" is null
at com.jaamsim.events.EventManager.execute(EventManager.java:277)
at com.jaamsim.events.Process.run(Process.java:98)
```

Somehow the `currentTick.get()` is null when using Julia ...

H J

unread,
Nov 22, 2025, 11:17:00 AM (8 days ago) Nov 22
to JaamSim Users Discussion Group
Solved: in Julia we have `print` and `println` statements (the latter being Python's equivalent of `print`); the server output must be terminated by an `\n` character; hence, use `println`.
Reply all
Reply to author
Forward
0 new messages