Python Forum
threads inside a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
threads inside a function
#1
i have a function that needs to send a buffered stream of bytes through a process and read the results back. the process could be blocked if its output pipe fills up or its input pipe goes empty. so this function needs to be able to interleave writing and reading these two pipes for as long and there is data to send. the process may expand on the data significantly, resulting in large amounts of data to read when there is little to write. the process may be doing this synchronously.

i would like to know if a function can start a couple threads, one to fetch data from the output buffer and write it to its pipe, and the other to read from the other pipe and store it in the other buffer, and when both threads are done, let the function clean up and return to its caller.

the goal is to be able to implement synchronous reading and writing code in the two threads rather that making this work using system specific calls like select(). this would be to make this script the most portable it can be.

one concern i have is launching threads that do this within a function call. another concern is if the caller also has threads running.

what kinds of issues would need to consider? i want to does all this in the function and impose nothing on the caller.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function defined inside a function Skaperen 2 2,436 May-13-2021, 01:04 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020