# Failed to create a child event loop

**URL:** <https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 24, 2020, 12:41pm UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972 "2020-06-24T12:41:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nouh.qaoud](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nouh.qaoud](https://forum.inductiveautomation.com/u/nouh.qaoud)\
**Post date:** [June 24, 2020, 12:41pm UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972/1 "2020-06-24T12:41:29Z")

</div>

Dears  
I have “gateway start up” script which listing to port 31001 , it works well.  
when i active telent script in port 23 , the startup scrip get the below error.

java.base/java.lang.reflect.Constructor.newInstance(Unknown Source) at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:211) java.lang.IllegalStateException: java.lang.IllegalStateException: failed to create a child event loop

Could you please help me about this issue.

Best Regards

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 24, 2020, 12:45pm UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972/2 "2020-06-24T12:45:26Z")

</div>

Are you listening to a port directly in your event script? That ties up a thread of the gateway’s event handling thread pool. Anyways, show your code.

---

<div class="post-metadata">

**Author:** ![nouh.qaoud](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nouh.qaoud](https://forum.inductiveautomation.com/u/nouh.qaoud)\
**Post date:** [June 24, 2020, 12:49pm UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972/3 "2020-06-24T12:49:33Z")

</div>

Kindly find script below

import socket  
host = ‘192.168.1.1’  
port=31001

while True:  
try:  
s = socket.socket(socket.AF\_INET, socket.SOCK\_STREAM)  
s.bind((host, port))  
s.listen(5)  
conn , addr =s.accept()  
system.tag.write("[default]addr",addr)  
while True:  
data = conn.recv(512)   
if not data :   
s.close()  
break  
else:  
system.tag.write("[default]data",data)  
conn.sendall(“ok”.encode())  
s.close()  
except:  
print (“TCP Listining Stopped”)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 24, 2020, 1:29pm UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972/4 "2020-06-24T13:29:12Z")

</div>

Please edit your post to include code markers. Use three backquotes above and below your code, so it looks like this in the editor:

```  
pasted code  
```

That said, you can’t loop forever in _ **any** _ event script. You must use system.util.invokeAsynchronous() to launch a _ **separate** _ thread.

---

<div class="post-metadata">

**Author:** ![nouh.qaoud](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nouh.qaoud](https://forum.inductiveautomation.com/u/nouh.qaoud)\
**Post date:** [July 5, 2020, 10:39am UTC](https://forum.inductiveautomation.com/t/failed-to-create-a-child-event-loop/35972/5 "2020-07-05T10:39:57Z")

</div>

Thanks for your help, i created script in project library with while loop to listen to specific port , and called it with system.util.invokeAsynchronous() in start up script , it worked well for a day then hanged , if i restart gateway ,it works again.

could you please help me about he best choice of running the script witch listen forever to specific port\>

Best Regards
