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?
CodePudding user response:
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