Comments (10)
I had a go at adding this feature tonight. over on a branch: https://github.com/daurnimator/cqueues/commits/thread-on-error
Please review :)
from cqueues.
On Sun, Jan 11, 2015 at 08:34:26PM -0800, daurnimator wrote:
I had a go at adding this feature tonight. over on a branch: https://github.com/daurnimator/cqueues/commits/thread-on-error
Please review :)
One of the TODO items I had in mind was to tweak cqueues:wrap and
cqueues:attach to return a unique identifier which could then be used to
communicate information about a context just like this.
The actual thread object is an obvious choice, but what if we want to
eventually recycle threads? If we provide context for errors, it would make
sense to also provide a way to communicate which threads finished normally.
If we use the thread object as the identifier returned from cqueues:attach
and :wrap, then we can't reycle the threads--maybe somebody put it in a weak
table so it could detect when it's GC'd.
But maybe that's not a particularly useful feature. It also conflicts with
the return signature and usage pattern of :step, and perhaps other
inconsistencies.
Your patch still works, but if something like the above was implement we
might need to return 4 values.
from cqueues.
The actual thread object is an obvious choice, but what if we want to
eventually recycle threads?
Well that doesn't work with :attach
anyway.
Reusing threads with :wrap
is interesting though.
If we provide context for errors, it would make
sense to also provide a way to communicate which threads finished normally.
If we use the thread object as the identifier returned from cqueues:attach
and :wrap, then we can't reycle the threads--maybe somebody put it in a weak
table so it could detect when it's GC'd.
Does it?
You cannot recycle a thread that has had an error, it is "dead"
(as returned by coroutine.status
).
I limited the patch to this case (only errors), as there was nothing else you can use the thread object for again.
The actual 'thread' object is required, as I will want to be able to use it with the debug.*
apis that take a thread as a first parameter.
But maybe that's not a particularly useful feature. It also conflicts with
the return signature and usage pattern of :step, and perhaps other
inconsistencies.Your patch still works, but if something like the above was implement we
might need to return 4 values.
I think returning the thread in the :step()
failure case is absolutely fine.
What to return in the success/running case can be left as an open question.
from cqueues.
Any more thoughts here?
from cqueues.
I'm sold. Only question mark is what the return signature should be for :step. Should it be
local ok, errmsg, errno, thr = loop:step()
or
local ok, errmsg, errno_or_thr = loop:step()
or something else? Some errors might not be related to a specific thread. Or a thread error might have an associated errno.
from cqueues.
Hmm, I didn't think about errno. at least in the handler I modified in my branch I didn't see it...
Or a thread error might have an associated errno.
How would that occur?
from cqueues.
Infact, are there any circumstances where :step
returns an errno?
from cqueues.
Right now, no. But that's because we either throw on error, or discard the errno after formatting the error message. Even if we return the thread, some of those thread errors involve a system error that we would want to return directly so the user doesn't have to parse the message.
I'm thinking maybe the return signature should look like:
local ok, msg, errno, thr = loop:step()
or even
local ok, msg, errno, thr, obj = loop:step()
were obj
is the object that triggered the error.
The most common error will likely be en error thrown by the thread itself, in which case errno will be nil
and it might seem dumb to have a hole in the list like that. But it seems the best out of all the alternatives. Thoughts?
from cqueues.
Right now, no.
So lets add it if we think it's reasonable. Should be lua_pushinteger(L, error)
at line 1671: https://github.com/wahern/cqueues/blob/master/src/cqueues.c#L1671 and then an extra thing to xmove
I'm thinking maybe the return signature should look like:
local ok, msg, errno, thr = loop:step()
or evenlocal ok, msg, errno, thr, obj = loop:step()
were obj is the object that triggered the error.
Lets go with the former for now. we can add the poll object later if it seems to be required.
from cqueues.
Fixed with 0c43868, followed by bug fix in 8f6645f.
from cqueues.
Related Issues (20)
- Consider removing the debian/ dir (or moving it to another place) HOT 1
- error thrown from sleep: attempt to call a userdata value HOT 3
- installing on debian 9 using luarocks 3.3 with lua 5.1 fails HOT 2
- The codes are so urgly!
- lua 5.1 can import cqueues, luajit cannot HOT 1
- lua 5.3 build failed HOT 1
- Lua 5.4 support HOT 1
- cqueues unusable on aarch64 under LuaJIT HOT 21
- cqueues.notify: removing file from notify object
- cqueues.lua:85 expected 1 arguments, got 5 HOT 4
- Nesting controllers / parent discovery HOT 2
- Luarocks install fails on arm64 mac HOT 4
- starttls issue (unable to update event disposition: No such file or directory) HOT 4
- cqueues fails install within a Docker image; states 5.2-1 version is provided, when 5.2 is required HOT 2
- Does not build on raspbian HOT 5
- undefined symbol:CRYPTO_set_locking_callback HOT 2
- Working on the arm-linux board , and the compile is so complex HOT 1
- Does not build on OpenBSD 7.2
- cqueues doesn't work on FreeBSD 13.1
- Build fails under illumos + epoll gaps? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqueues.