0

I am new to python and HTTP request, and I am trying to implement HTTP request between two functions, which I am not sure will work. Can you read my thoughts and give me some suggestions/examples on how to implement them?

Here's what I expect: Let's call these two functions A and B; B is the while true loop, and both A and B are in different threads.

When A receive a post request with a body
B will create a txt file in my file system
A will receive the txt file path and write "hello world" into it

Is that something I can do with python and HTTP request. My intutitive thought is I can use thread and lock to implement it, but I am not sure on how to do it. Can you give me some idea or suggestions?

  • Is there any specific reason you are using threading to achieve it ? – Vimalan E Dec 06 '22 at 18:35
  • [asyncio: Wait for event from other thread](https://stackoverflow.com/questions/33000200/asyncio-wait-for-event-from-other-thread) – wwii Dec 07 '22 at 00:03

1 Answers1

0

some idea or suggestions?

  • Use two Events created in the main thread
  • One event signals 'B' to make a text file
  • The other signals 'A' that a new file has been made
  • Probably could make it work with one Event
    • 'A' sets the event then waits/loops till it is clear
    • 'B' waits for the Event to set then makes a file and clears the even
  • Use a module level variable in the main thread to hold the file name
    • 'B' modifies the variable.
    • 'A' reads the variable.

Or

  • Use Queue's to send signals and info between threads
wwii
  • 23,232
  • 7
  • 37
  • 77