# How to call PythonCall.jl behind a julia HTTP webserver?

**URL:** <https://discourse.julialang.org/t/how-to-call-pythoncall-jl-behind-a-julia-http-webserver/119563>\
**Category:** General Usage\
**Tags:** question, multithreading, http, pythoncall\
**Created:** [September 18, 2024, 4:26pm UTC](https://discourse.julialang.org/t/how-to-call-pythoncall-jl-behind-a-julia-http-webserver/119563 "2024-09-18T16:26:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [September 18, 2024, 4:26pm UTC](https://discourse.julialang.org/t/how-to-call-pythoncall-jl-behind-a-julia-http-webserver/119563/1 "2024-09-18T16:26:33Z")

</div>

Hi there, I am wondering how I could use langchain from Python as part of a webserver.

I am running into segmenation faults certainly due to multithreading. Does someone know a way whether the new `@unlock` and `@lock` are enough for this use case? Or does someone know a good way to spawn threads on thread one (because that is where PythonCall locks the GIL by default)?

---

<div class="post-metadata">

**Author:** ![Joseph\_Gardi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joseph_gardi/32/212101_2.png) [@Joseph\_Gardi](https://discourse.julialang.org/u/Joseph_Gardi)\
**Post date:** [September 22, 2024, 8:49pm UTC](https://discourse.julialang.org/t/how-to-call-pythoncall-jl-behind-a-julia-http-webserver/119563/2 "2024-09-22T20:49:42Z")

</div>

Maybe you are using different terms than I am used to but I don’t think you can spawn thread 1. Thread 1 is the thread your program starts and ends with. I assume you mean like queueing a task on thread 1. I know that is common in swift and objective C but I’ve never seen that elsewhere. Usually not necessary.

Lock and unlock does not change which thread you are executing on. It prevents different threads from accessing the same data at the same time.

i would consider avoiding threads if it causes this extra complexity. Python web servers usually have no threading but use async instead. Julia has async too.  
At least don’t lose track of the main thread which the program started in.

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [September 24, 2024, 2:09pm UTC](https://discourse.julialang.org/t/how-to-call-pythoncall-jl-behind-a-julia-http-webserver/119563/3 "2024-09-24T14:09:21Z")

</div>

the thing is that the webserver will use all available threads to distribute the load, so that if I have a PythonCall call inside the web response, it may be run from another thread than 1

It actually seems to work with unlock and lock for now…
