GVKun编程网logo

从Python代码返回C ++时,Python PyGILState_ {Ensure / Release}导致段错误(python返回到某处指令)

13

如果您想了解从Python代码返回C++时,PythonPyGILState_{Ensure/Release}导致段错误的相关知识,那么本文是一篇不可错过的文章,我们将对python返回到某处指令进行

如果您想了解从Python代码返回C ++时,Python PyGILState_ {Ensure / Release}导致段错误的相关知识,那么本文是一篇不可错过的文章,我们将对python返回到某处指令进行全面详尽的解释,并且为您提供关于1行Python代码,把Excel转成PDF,python-office功能更新~、C & python联合编程-解决PyGILState_Ensure死锁问题、C#中的Python脚本通过C#传递值并从python代码获取返回值、Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习的有价值的信息。

本文目录一览:

从Python代码返回C ++时,Python PyGILState_ {Ensure / Release}导致段错误(python返回到某处指令)

从Python代码返回C ++时,Python PyGILState_ {Ensure / Release}导致段错误(python返回到某处指令)

更新
嗯,看起来好像在调用PyGILState_Ensure()之前就添加了PyEval_InitThreads()。我急于想办法,将我的“悬挂”错误地归因于PyEval_InitThreads()。

但是,在阅读了一些Python文档之后,我想知道这是否是正确的解决方案。

当未知哪个线程(如果有)当前具有全局解释器锁时,调用此函数是不安全的。


首先,我正在研究一些修改的GNU Radio代码-
特别是修改的gr_bin_statistics_f块。现在,有一个错误报告(尽管是一个旧报告),几乎可以描述我的确切情况。

http://gnuradio.org/redmine/issues/show/199

现在,在错误报告中提到的usrp_spectrum_sense.py调用gr_bin_statistics_f(C
++),然后定期调用Python以重新调整USRP(无​​线电)。

调用Python代码时,会发生以下情况:

PyGILState_STATE d_gstate;
d_gstate = PyGILState_Ensure();

// call python code

PyGILState_Release(d_gstate);

因此,一旦我们从Python代码返回,则在调用PyGILState_Release(d_gstate)时会发生分段错误。尽管我的代码与原始的gr_bin_statistics_f之间存在差异,但似乎没有任何远程关系。

我读到在PyGILState_Ensure()解决某些问题之前调用PyEval_InitThreads(),但这只会导致程序挂起。

谁能为我阐明这一点?还是只是将消息发送到GNU Radio邮件列表的时间?

在Fedora 14 x86_64上使用Python2.7。

这是GDB回溯:

(gdb) c
Continuing.
[New Thread 0x7fabd3a8d700 (LWP 23969)]
[New Thread 0x7fabd328c700 (LWP 23970)]
[New Thread 0x7fabd2a8b700 (LWP 23971)]
[New Thread 0x7fabd228a700 (LWP 23972)]
[New Thread 0x7fabd1a89700 (LWP 23973)]
[New Thread 0x7fabd1288700 (LWP 23974)]
[New Thread 0x7fabd0a87700 (LWP 23975)]
[New Thread 0x7fabbbfff700 (LWP 23976)]

Program received signal SIGSEGV,Segmentation fault.
[Switching to Thread 0x7fabbbfff700 (LWP 23976)]
0x00000036b3e0db00 in sem_post () from /lib64/libpthread.so.0
(gdb) bt
#0  0x00000036b3e0db00 in sem_post () from /lib64/libpthread.so.0
#1  0x00000036c1317679 in PyThread_release_lock () from /usr/lib64/libpython2.7.so.1.0
#2  0x00007fabd6159c1f in ~ensure_py_gil_state (this=0x2dc6fc0,x=887000000)
    at gnuradio_swig_py_general.cc:5593
#3  gr_py_feval_dd::calleval (this=0x2dc6fc0,x=887000000) at gnuradio_swig_py_general.cc:5605
#4  0x00007fabd77c4b6e in gr_noise_level_f::tune_window (this=0x2db3ca0,target_freq=) at gr_noise_level_f.cc:97
#5  0x00007fabd77c554b in gr_noise_level_f::work (this=0x2db3ca0,noutput_items=7,input_items=,output_items=)
    at gr_noise_level_f.cc:115
#6  0x00007fabd7860714 in gr_sync_block::general_work (this=0x2db3ca0,noutput_items=,ninput_items=,output_items=) at gr_sync_block.cc:64
#7  0x00007fabd7846ce4 in gr_block_executor::run_one_iteration (this=0x7fabbbffed90)
    at gr_block_executor.cc:299
#8  0x00007fabd7864332 in gr_tpb_thread_body::gr_tpb_thread_body (this=0x7fabbbffed90,block=...)
    at gr_tpb_thread_body.cc:49
#9  0x00007fabd785cce7 in operator() (function_obj_ptr=...) at gr_scheduler_tpb.cc:42
#10 operator() (function_obj_ptr=...)
    at /home/tja/Research/energy/detector/gnuradio-3.3.0/gruel/src/include/gruel/thread_body_wrapper.h:49
#11 boost::detail::function::void_function_obj_invoker0,void>::invoke (function_obj_ptr=...) at /usr/include/boost/function/function_template.hpp:153
---Type  to continue,or q  to quit---
#12 0x00007fabd74914ef in operator() (this=)
    at /usr/include/boost/function/function_template.hpp:1013
#13 boost::detail::thread_data >::run (this=)
    at /usr/include/boost/thread/detail/thread.hpp:61
#14 0x00007fabd725ca55 in thread_proxy () from /usr/lib64/libboost_thread-mt.so.1.44.0
#15 0x00000036b3e06d5b in start_thread () from /lib64/libpthread.so.0
#16 0x00000036b3ae4a7d in clone () from /lib64/libc.so.6
(gdb)

感谢您的光临!

1行Python代码,把Excel转成PDF,python-office功能更新~

1行Python代码,把Excel转成PDF,python-office功能更新~

大家好,这里是程序员晚枫。

今天给大家分享一个Python自动化办公的专用库python-office的最新功能:1行代码,实现Excel转PDF。

更多功能,请见官网:开源中国推荐:python-office自动化办公,每个功能只需一行代码,做到了真正的开箱即用。

1、上代码

首先,下载python-office,下载教程之前录制过了,大家可以去看看~

点我直达

其次,1行代码调用ppt转图片的功能。

import office

office.excel.excel2pdf(excel_path=r"D:\test\程序员晚枫.xlsx",
                       pdf_path=r"D:\test\程序员晚枫.pdf")

2、参数说明

一共有2个参数,作用分别如下:

  • excel_path = r"D:\test\程序员晚枫.xlsx" # 这里是Excel文件的路径
  • pdf_path = r"D:\test\程序员晚枫.pdf" # 这里是输出PDF的保存路径

大家在使用中有任何问题,欢迎在评论区和我交流~

C & python联合编程-解决PyGILState_Ensure死锁问题

C & python联合编程-解决PyGILState_Ensure死锁问题

GIL锁机制

GIL本质就是一把互斥锁,既然是互斥锁,所有互斥锁的本质都一样,都是将并发运行变成串行,以此来控制同一时间内共享数据只能被一个任务所修改,进而保证数据安全。保护不同的数据的安全,就应该加不同的锁。
  每执行一个python程序,就是开启一个进程,在一个python的进程内,不仅有其主线程或者由该主线程开启的其他线程,还有解释器开启的垃圾回收等解释器级别的线程,所有的线程都运行在这一个进程内,所以:
1、所有数据都是共享的,这其中,代码作为一种数据也是被所有线程共享的(test.py的所有代码以及cpython解释器的所有代码)
2、所有线程的任务,都需要将任务的代码当做参数传给解释器的代码去执行,即所有的线程要想运行自己的任务,首先需要解决的是能够访问到解释器的代码。
(摘自https://blog.csdn.net/qq_17513503/article/details/81062510)


PyGILState_Ensure获取不到锁的问题典型示例以及解决方法:

PyGILState_Ensure一般用在面向C语言的回调函数调用python的函数对象之前,在调用它时,会向python解释器请求GIL资源,此时如果刚好有一个python函数已经获取了GIL,且需要等待回调函数执行完毕才能退出。如下图所示。

image.png

这种情况就会导致死锁,卡在func等待回调执行完毕这里。所以在这种情况下,需要使python解释器调用的函数先释放GIL,等待回调结束后,再执行。
示例:

image.png

C#中的Python脚本通过C#传递值并从python代码获取返回值

C#中的Python脚本通过C#传递值并从python代码获取返回值

如何解决C#中的Python脚本通过C#传递值并从python代码获取返回值?

我正在用 C# 制作一个 GUI 并使用铁 python 编写 python 脚本。但我想将 C# 代码中的值传递给 python 代码,并获取返回值以显示在我的 gui 中。可以吗???

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习

Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习

http://blog.csdn.net/pipisorry/article/details/44245575

关于怎么学习python,并将python用于数据科学、数据分析、机器学习中的一篇很好的文章

Comprehensive learning path – Data Science in Python

深度学习路径-用python进行数据学习

Journey from a Pythonnoob(新手) to a Kaggler on Python

So, you want to become a data scientist or may be you are already one and want toexpand(扩张) your toolrepository(贮藏室). You have landed at the right place. The aim of this page is to provide a comprehensive learning path to people new to python for data analysis. This path provides a comprehensiveoverview(综述) of steps you need to learn to use Python for data analysis. If you already have some background, or don’t need all thecomponents(成分), feel free toadapt(适应) your own paths and let us know how you made changes in the path.

Step 0: Warming up

Before starting your journey, the first question to answer is:

Why use Python?

or

How would Python be useful?

Watch the first 30 minutes of this talk from Jeremy, Founder of DataRobot at PyCon 2014, Ukraine to get an idea of how useful Python could be.

 

Step 1: Setting up your machine

Now that you have made up your mind, it is time to set up your machine. The easiest way toproceed(开始) is to justdownload Anaconda from Continuum.io . It comes packaged with most of the things you will need ever. The majordownside(下降趋势) of taking thisroute(路线) is that you will need to wait for Continuum to update their packages, even when there might be an update available to theunderlying(潜在的) libraries. If you are a starter, that should hardly matter.

If you face any challenges in installing(安装), you can find moredetailed instructions for various OS here

 

Step 2: Learn the basics of Python language

You should start by understanding the basics of the language, libraries and datastructure(结构). The python track fromCodecademy is one of the best places to start your journey. By end of this course, you should be comfortable writing small scripts on Python, but also understand classes and objects.

Specifically learn: Lists, Tuples, Dictionaries, List comprehensions(理解), Dictionary comprehensions 

Assignment: Solve the python tutorial(辅导的) questions on HackerRank. These should get your brain thinking on Python scripting

Alternate resources: If interactive(交互式的) coding is not your style of learning, you can also look at TheGoogle Class for Python. It is a 2 day class series and also covers some of the parts discussed later.

 

Step 3: Learn Regular Expressions in Python

You will need to use them a lot for data cleansing(净化), especially if you are working on text data. The best way to learn Regular expressions is to go through the Google class and keep this cheat sheet handy.

Assignment: Do the baby names exercise

If you still need more practice, follow this tutorial(个别指导) for text cleaning. It will challenge you on various stepsinvolved(包含) in datawrangling(争论).

Step 4: Learn Scientific libraries in Python – NumPy, SciPy, Matplotlib and Pandas

This is where fun begins! Here is a brief introduction to various libraries. Let’s start practicing some common operations.

  • Practice the NumPy tutorial thoroughly, especially NumPy arrays(数组). This will form a goodfoundation(基础) for things to come.
  • Next, look at the SciPy tutorials. Go through the introduction and the basics and do the remaining onesbasis(基础) your needs.
  • If you guessed Matplotlib tutorials next, you are wrong! They are too comprehensive(综合的) for our need here. Instead look at thisipython notebook till Line 68 (i.e. till animations(活泼))
  • Finally, let us look at Pandas. Pandas provide DataFrame functionality(功能) (like R) for Python. This is also where you should spend good time practicing. Pandas would become the mosteffective(有效的) tool for all mid-size data analysis. Start with a short introduction,10 minutes to pandas. Then move on to a more detailedtutorial on pandas.

You can also look at Exploratory(勘探的) Data Analysis with Pandas andData munging with Pandas

Additional Resources:

  • If you need a book on Pandas and NumPy, “Python(巨蟒) for Data Analysis by Wes McKinney”
  • There are a lot of tutorials(个别指导) as part of Pandasdocumentation(文件材料). You can have a look at themhere

Assignment: Solve this assignment(分配) from CS109 course from Harvard.

 

Step 5: Effective Data Visualization

Go through this lecture form CS109. You can ignore(驳回诉讼) the initial 2 minutes, but what follows after that isawesome(可怕的)! Follow this lecture up withthis assignment

 

Step 6: Learn Scikit-learn and Machine Learning

Now, we come to the meat of this entire process. Scikit-learn is the most useful library onpython(巨蟒) for machine learning. Here is abriefoverview(综述) of the library. Go through lecture 10 to lecture 18 fromCS109 course from Harvard. You will go through an overview of machine learning, Supervised learningalgorithms(算法) likeregressions(回归), decision trees,ensemble(全体) modeling and non-supervised learning algorithms likeclustering(聚集). Followindividual(个人的) lectures with theassignments from those lectures.

 

Additional Resources:

  • If there is one book, you must read, it is Programming Collective Intelligence – a classic(经典的), but still one of the best books on the subject.
  • Additionally(附加的), you can also follow one of the best courses onMachine Learning course from Yaser Abu-Mostafa. If you need more lucid(明晰的) explanation for the techniques, you can opt for theMachine learning course from Andrew Ng and follow the exercises on Python.
  • Tutorials(个别指导) on Scikit learn

Assignment: Try out this challenge on Kaggle

 

Step 7: Practice, practice and Practice

Congratulations, you made it!

You now have all what you need in technical skills. It is a matter of practice and what better place to practice than compete with fellow Data Scientists on Kaggle. Go, dive into one of the live competitions currently running onKaggle and give all what you have learnt a try!

 

Step 8: Deep Learning

Now that you have learnt most of machine learning techniques, it is time to give Deep Learning a shot. There is a good chance that you already know what is Deep Learning, but if you still need a briefintro(介绍),here it is.

I am myself new to deep learning, so please take these suggestions with apinch(匮乏) of salt. The mostcomprehensive(综合的) resource isdeeplearning.net. You will find everything here – lectures, datasets, challenges, tutorials. You can also try thecourse from Geoff Hinton a try in a bid to understand the basics of Neural Networks.

 

P.S. In case you need to use Big Data libraries, give Pydoop and PyMongo a try. They are not included here as Big Data learning path is an entire topic in itself.

from: http://blog.csdn.net/pipisorry/article/details/44245575

ref:http://www.analyticsvidhya.com/learning-paths-data-science-business-analytics-business-intelligence-big-data/learning-path-data-science-python/

全中文


关于从Python代码返回C ++时,Python PyGILState_ {Ensure / Release}导致段错误python返回到某处指令的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于1行Python代码,把Excel转成PDF,python-office功能更新~、C & python联合编程-解决PyGILState_Ensure死锁问题、C#中的Python脚本通过C#传递值并从python代码获取返回值、Comprehensive learning path – Data Science in Python深度学习路径-用python进行数据学习的相关知识,请在本站寻找。

本文标签: