Code Monkey home page Code Monkey logo

learninggolang's People

Contributors

woshidama323 avatar

Stargazers

Sean Brennan avatar

learninggolang's Issues

钉钉消息 html转图片总结

在golang 自行调度的场景下,wkhtmltoimage (wkhtmltopdf)这个工具遇到的一些问题

  1. 因为依赖qt 而qt 需要在主线程中创建application
WARNING: QApplication was not created in main() thread

这样造成的后果是 因为qt没有初始化好,后面转换出现了乱码

  1. cgo调用c代码的时候,如果go的调度器切换了线程,那么cgo有可能会失败
    cgo Interacting with C Library that uses Thread Local Storage
//https://github.com/bratsche/glib/blob/master/glib/gmain.c
/**
 * g_main_context_pop_thread_default:
 * @context: a #GMainContext object, or %NULL
 *
 * Pops @context off the thread-default context stack (verifying that
 * it was on the top of the stack).
 *
 * Since: 2.22
 **/
void
g_main_context_pop_thread_default (GMainContext *context)
{
  GQueue *stack;

  if (context == g_main_context_default ())
    context = NULL;

  stack = g_static_private_get (&thread_context_stack);

  g_return_if_fail (stack != NULL);
  g_return_if_fail (g_queue_peek_head (stack) == context);

  g_queue_pop_head (stack);

  g_main_context_release (context);
  if (context)
    g_main_context_unref (context);
}
(process:14437): GLib-CRITICAL **: 03:30:03.635: g_main_context_pop_thread_default: assertion 'stack != NULL' failed
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x7fb271104041]

runtime stack:
runtime.throw(0x117aaed, 0x2a)
	/usr/local/go/src/runtime/panic.go:1116 +0x72
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:726 +0x4ac

goroutine 23316 [syscall]:
runtime.cgocall(0xef1610, 0xc0008c99e8, 0xc0008c99f0)
	/usr/local/go/src/runtime/cgocall.go:133 +0x5b fp=0xc0008c99b8 sp=0xc0008c9980 pc=0x4058bb
github.com/shezadkhan137/go-wkhtmltoimage._Cfunc_wkhtmltoimage_deinit(0x0)
	_cgo_gotypes.go:143 +0x49 fp=0xc0008c99e8 sp=0xc0008c99b8 pc=0xd779a9
github.com/shezadkhan137/go-wkhtmltoimage.Destroy()

最终的解决办法是用

runtime.LockOSThread()
runtime.UnlockOSThread()
通过不让调度器切换线程来避免这样的问题这样的操作当然是有代价的 性能会下降

中台定时任务故障排查跟踪

golang 调度研究

hell hello heh
os层 最大线程数量
https://stackoverflow.com/questions/344203/maximum-number-of-threads-per-process-in-linux

golang 最大线程数量 10000 
可以通过 runtime debug 包中的SetMaxThreads() 来设置  

创建的条件是,
当前的thread 如果被block 了 (比如在io等待)将会重新创建一个新的os层的thread 来继续工作
It will create a new thread once current one is blocked.

golang实现接口注意事项

简介

golang实现接口有很多需要注意的地方

var dataSlice []int = foo()
var interfaceSlice []interface{} = dataSlice

Why can't I assign any slice to an []interface{}

原因:
[]interface{} is not an interface!
长度不一样 []interface{} 占两个words 一个是类型,一个是内容或者指针 对于N长的数据总长是 N*2

如果非要用 可以这样

var dataSlice []int = foo()
var interfaceSlice []interface{} = make([]interface{}, len(dataSlice)) //这里指定已知类型的长度
for i, d := range dataSlice {
	interfaceSlice[i] = d
}

参考资料

golang 引入私有repo

参考资料

go env -w GOPRIVATE=github.com/woshidama323/FILECOIN

来源

注意:

加私有仓储 需要提供当前环境的 ssh public key到github私有仓储中

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.