[编程]ipython后台任务多线程执行

背景 jupyter notebook是以ipython为内核的,在编写程序的时候,经常遇到有些高IO的函数在后台运行半天,但是又需要在它运行的时候执行别的任务,因此这就用到了多线程。 其实ipython 已经封装好了多线程工具,只需要调用即可执行 简单使用 from IPython.lib import backgroundjobs as bg from time import sleep jobs = bg.BackgroundJobManager() def func1(): sleep(1000000) return 1 # 创建任务 jobs.new(func1) # 任务状态 jobs.status() # Running jobs: # 0 : <function func1 at 0x7fae1b670c80> # 执行结果 result=jobs.result(0) 官方代码 版权声明:本文为 m2kar 的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 作者: m2kar 打赏链接: 欢迎打赏m2kar 邮箱: m2kar.cn#gmail.com 主页: m2kar.cn Github: github.com/m2kar CSDN: M2kar的专栏

C语言中常用的调试宏

背景 在C语言编写中,经常想因为调试的原因,插入一些临时输出的变量,或者执行一些不必要的指令。 写完之后频繁注释和反注释很耗时间,而且可能会造成不必要的错误。 因此作者采用了宏命令的方式,插入一些调试输出。 代码 // File: debug.c // some debug Macro // #define DEBUG #ifndef DEBUG_PRINT #ifdef DEBUG #define DEBUG_PRINT(fmt, args...) fprintf(stderr, fmt, ## args) #else #define DEBUG_PRINT(fmt, args...) /* Don't do anything in release builds */ #endif #endif //DEBUG_PRINT #ifndef DEBUG_RUN #ifdef DEBUG #define DEBUG_RUN(args) {args ; } #else #define DEBUG_RUN(args...) #endif #endif //DEBUG_RUN 使用方式 将上述代码加入到头文件中。 Gcc编译时加入-DDEBUG定义DEBUG宏 gcc -DDEBUG -o ./a.out 对于DEBUG_PRINT,在代码中像正常printf一样使用。 对于DEBUG_RUN,在括号中的语句只有在DEBUG模式下才会执行。 //File: main.c #include <stdio.h> #include "debug....

十一月 19, 2019 · 1 分钟 · M2kar

【论文笔记】Beyond credential stuffing: Password similarity models using neural networks

论文主题 同一用户在不同网站的密码相似度模型。 摘要 英文 Attackers increasingly use passwords leaked from one website to compromise associated accounts on other websites. Such targeted attacks work because users reuse, or pick similar, passwords for different websites. We recast one of the core technical challenges underlying targeted attacks as the task of modeling similarity of human-chosen passwords. We show how to learn good password similarity models using a compilation of 1.4 billion leaked email, password pairs....

十一月 15, 2019 · 4 分钟 · M2kar

【论文笔记】Birthday, Name and Bifacial-security Understanding Passwords of Chinese Web Users

论文主题 对中文密码进行实证分析,发现中文密码中有趣的结构和特征,揭示了中文密码的双相安全性(Bifacial-security)。 摘要 英文 Much attention has been paid to passwords chosen by English speaking users, yet only a few studies have examined how non-English speaking users select passwords. In this paper, we perform an extensive, empirical analysis of 73.1 million real-world Chinese web passwords in comparison with 33.2 million English counterparts. We highlight a number of interesting structural and semantic characteristics in Chinese passwords. We further evaluate the security of these passwords by employing two state-of-the-art cracking techniques....

十月 24, 2019 · 2 分钟 · M2kar

【论文笔记】GENPass: A general deep learning model for password guessing with PCFG rules and adversarial generation

论文主题 使用RCFG+LSTM和对抗生成网络猜解密码。 摘要 英文 Password has become today’s dominant method of authentication in social network. While the brute-force attack methods, such as HashCat and John the Ripper, are unpractical, the research then switches to the password guess. The state-of-the-art approaches, such as Markov Model and probabilistic context-free grammars(PCFG), are all based on statistical probability. These approaches have a low matching rate. The methods on neural network have been proved more accurate and practical for password guessing than traditional methods....

十月 18, 2019 · 2 分钟 · M2kar