Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement thread priority into sleeping threads #61

Closed
wants to merge 1 commit into from

Conversation

FiniteReality
Copy link

In a project I was using copas in, I was having issues where copas would not resume a thread correctly which would lead to disconnects with the websocket API I was using, as the connection was timing out because I wasn't able to send a 'heartbeat' when I needed to.

This PR adds a mechanism for setting the priority of a thread as it yields, which in my case alleviated the problem as I could set the priority of the thread which was handling the heartbeats to a fairly high value to ensure it would always be checked in the main loop.

This should allow threads just about to sleep to set a priority
to be resumed, meaning that more important threads get resumed
before less important threads.
@coveralls
Copy link

coveralls commented Dec 26, 2016

Coverage Status

Changes Unknown when pulling 146f252 on FiniteReality:master into ** on keplerproject:master**.

@Tieske
Copy link
Member

Tieske commented Jan 10, 2017

Wondering, if connections timeout, then something else is blocking for too long. So maybe you have another underlying issue here?

Or am I not getting it?

@Tieske
Copy link
Member

Tieske commented Jun 19, 2017

@FiniteReality ping any update on this?

@FiniteReality
Copy link
Author

Oh wow, I forgot all about this PR. As for things that were blocking, I think the flow was something like this:

  • Add thread to read data from a socket (I'm using copas in a client-style situation as something like libuv/libev, because I haven't gotten around to learning it yet 😛)
  • Add thread to send data on same socket (The protocol over said socket requires I send a "heartbeat" every 40s or so to ensure my connection stays alive)

Since both "threads" require a constantly running while loop, to allow other code to run I need to yield control to something else, but I couldn't manage to get a socket read to yield until data was available (this is likely my problem) so I ended up hacking something into copas where I could specify "resume this one first if possible" which fixed my problem.

Of course, I haven't touched said code for a long while so I'm not entirely sure if that was the case.

@Tieske
Copy link
Member

Tieske commented Feb 11, 2020

let's close this for now. If thread priority comes up again we can have another look.

@Tieske Tieske closed this Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants