在这篇文章中,我们将带领您了解交互式Python:尽管line_profiler正确导入,但无法使%lprun正常工作的全貌,同时,我们还将为您介绍有关android–fb://profile/{us
在这篇文章中,我们将带领您了解交互式Python:尽管line_profiler正确导入,但无法使%lprun正常工作的全貌,同时,我们还将为您介绍有关android – fb:// profile / {userid}似乎无法正常工作、asp.net – 如何使用AspNetSqlMembershipProvider正确验证mvc-mini-profiler、c# – MvcMiniProfiler无法转换EFProfiledDbConnection类型的对象、File "/opt/python/anaconda3/lib/python3.7/subprocess.py", line 152, in
- 交互式Python:尽管line_profiler正确导入,但无法使%lprun正常工作
- android – fb:// profile / {userid}似乎无法正常工作
- asp.net – 如何使用AspNetSqlMembershipProvider正确验证mvc-mini-profiler
- c# – MvcMiniProfiler无法转换EFProfiledDbConnection类型的对象
- ">File "/opt/python/anaconda3/lib/python3.7/subprocess.py", line 152, in
交互式Python:尽管line_profiler正确导入,但无法使%lprun正常工作
问题
大多数IPython的“神奇功能”的工作对我罚款马上蝙蝠: %hist
,%time
,%prun
等。然而,我注意到,%lprun
无法IPython中找到,因为我想最初安装它。
尝试解决
然后,我发现我应该安装该line_profiler
模块。我已经安装了此模块,但是似乎仍然无法使magic函数正常工作。如果我尝试调用%lprun
,iPython
仍然找不到该函数。如果我用全名(line_profiler.magic_lprun)
调用它,则可以找到该函数,但根本无法使它正常工作。下面是我所做的示例(从“ Python for Data Analysis”
一书中逐步学习):
成功使用 %prun
[在:]
def add_and_sum(x, y): added = x + y summed = added.sum(axis=1) return summedx = randn(3000, 3000)y = randn(3000, 3000)add_and_sum(x, y)
有了这个,我得到了一个不错的答案,正如预期的那样:
[输出:]
array([-23.6223074 , -10.08590736, -31.2957222 , ..., -14.17271747, 63.84057725, -50.28469621])
而且我可以执行分析魔术功能%prun:
[在:]
%prun add_and_sum(x, y)
[输出:]
6 function calls in 0.042 secondsOrdered by: internal timencalls tottime percall cumtime percall filename:lineno(function) 1 0.020 0.020 0.029 0.029 <ipython-input-27-19f64f63ba0a>:1(add_and_sum) 1 0.013 0.013 0.042 0.042 <string>:1(<module>) 1 0.009 0.009 0.009 0.009 {method ''reduce'' of ''numpy.ufunc'' objects} 1 0.000 0.000 0.009 0.009 _methods.py:16(_sum) 1 0.000 0.000 0.009 0.009 {method ''sum'' of ''numpy.ndarray'' objects} 1 0.000 0.000 0.000 0.000 {method ''disable'' of ''_lsprof.Profiler'' objects}
使用失败 %lprun
但是,当我尝试时%lprun,我什么也得不到:
[在:]
%lprun -f add_and_sum add_and_sum(x, y)
[输出:]
ERROR: Line magic function `%lprun` not found.
而且,如果我尝试使用其标准名称调用该函数,那么它也将不起作用:
[在:]
line_profiler.magic_lprun -f add_and_sum.test test.add_and_sum(x, y)
[输出:]
line_profiler.magic_lprun -f add_and_sum.test test.add_and_sum(x, y) ^SyntaxError: invalid syntax
但是该库已正确导入,或者至少是这样写的:
[在:]
line_profiler
[输出:]
<module ''line_profiler'' from ''/Users/<edit>/anaconda/lib/python2.7/site-packages/line_profiler-1.0b3-py2.7-macosx-10.5-x86_64.egg/line_profiler.pyc''>
[在:]
line_profiler.magic_lprun
[输出:]
<function line_profiler.magic_lprun>
似乎还有一些我应该配置的东西,这样我添加的这些新魔术功能就可以被识别出来。我无法通过网络搜索找到任何东西。
我将Spyder作为IDE运行(仍然使用iPython作为控制台),但是我也直接在iPython和iPython Notebook中对其进行了尝试。我没有任何形式的运气。
答案1
小编典典要进行%lprun工作,您需要使用以下命令将扩展加载到会话中:
In [1]: %load_ext line_profiler
查看此笔记本,查看一些使用魔术的示例。
此外,如果您正在使用Spyder,则还有一个第三方line_profiler插件
android – fb:// profile / {userid}似乎无法正常工作
>它是来自facebook的安全更新.
用特定用户页面启动应用程序的任何其他方式.
解决方法
从这里学到了它:http://binwaheed.blogspot.com.ar/2014/06/android-open-facebook-official-app-from.html
如果你需要回退到浏览器,你应该实现这样的事情:
Intent intent = null; try { // get the Facebook app if possible this.getPackageManager().getPackageInfo("com.facebook.katana",0); intent = new Intent(Intent.ACTION_VIEW,Uri.parse("fb://page/{id}")); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } catch (Exception e) { // no Facebook app,revert to browser intent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://facebook.com/PROFILENAME")); } this.startActivity(intent);
asp.net – 如何使用AspNetSqlMembershipProvider正确验证mvc-mini-profiler
仅检查Request.IsLocal工作正常.
if(Request.IsAuthenticated) { if(User.IsInRole("Admin"); MiniProfiler.Start(); }
任何想法或为什么它不工作或更好的方法呢?
[更新]我接受了这个遮阳篷,但是没有弄清楚它,因为我没有做到这一点
我做了以下操作,但是分析器最初没有出现.
经过几次尝试,它开始显示,即使我尝试使用无痕模式访问该网站,所以没有cookie.
protected void Application_PostAuthorizeRequest(Object sender,EventArgs e) { if (User.IsInRole("Admin")) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler"); if (cookie == null) { cookie = new HttpCookie("RoleProfiler"); cookie.Value = "yes"; cookie.Expires = DateTime.Now.AddDays(1d); Response.Cookies.Add(cookie); } } }
我正在检查
protected void Application_BeginRequest(Object sender,EventArgs e) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler"); if ((cookie != null) && (cookie.Value == "yes") ) { MvcMiniProfiler.MiniProfiler.Start(); } }
并在请求结束时结束.
protected void Application_EndRequest() { MvcMiniProfiler.MiniProfiler.Stop(); }
[Update2]关闭问题,忽略这个,我是由outputcache所有.
解决方法
我解决了这个问题,如果用户在一个角色(在你的情况下为“Admin”),通过添加一个cookie,当请求被认证,那么你可以在开始请求和初始化分析器时检查这个cookie.
它不会第一次工作,但应该每次之后.
c# – MvcMiniProfiler无法转换EFProfiledDbConnection类型的对象
我的项目是
MVC 3
实体框架4.1(DatabaseFirst POCO Generator DbContext)
MvcMiniProfiler.dll 1.9.0.0
MvcMiniProfiler.EntityFramework.dll 1.9.1.0
我从Nu-Get安装了MvcMiniProfiler
下面添加到global.asax
protected void Application_BeginRequest() { if (Request.IsLocal) { MvcMiniProfiler.MiniProfiler.Start(); MiniProfilerEF.Initialize(); } }
下面添加到web.config
<system.data> <DbProviderFactories> <remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" /> <add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider" description="MvcMiniProfiler.Data.ProfiledDbProvider" type="MvcMiniProfiler.Data.ProfiledDbProviderFactory,MvcMiniProfiler,Version=1.8.0.0,Culture=neutral,PublicKeyToken=b44f9351044011a3" /> </DbProviderFactories> </system.data>
我得到了这个例外
system.invalidCastException was unhandled by user code Message=Unable to cast object of type 'MvcMiniProfiler.Data.EFProfiledDbConnection' to type 'System.Data.sqlClient.sqlConnection'. Source=System.Data StackTrace: at System.Data.sqlClient.sqlCommand.set_DbConnection(DbConnection value) at System.Data.Common.DbCommand.set_Connection(DbConnection value) at MvcMiniProfiler.Data.ProfiledDbCommand.set_DbConnection(DbConnection value) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\Data\ProfiledDbCommand.cs:line 118 at System.Data.Common.DbCommand.set_Connection(DbConnection value) at System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand,EntityTransaction entityTransaction,DbCommand storeProviderCommand) at System.Data.EntityClient.EntityCommandDeFinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context,ObjectParameterCollection parameterValues)
EF调用中发生异常
ModaEntitiesWrapper.GetInstance().Articles .AsNoTracking() .Where(p => p.StatusId == 1).ToList();
如果我将Web.Config中MvcMiniProfiler.Data.ProfiledDbProvider的版本从1.8.0.0更改为1.9.0.0
MiniProfilerEF.Initialize()调用中出现了一种新类型的异常.
system.indexOutOfRangeException was unhandled by user code Message=The given DaTarow is not in the current DaTarowCollection. Source=System.Data StackTrace: at System.Data.DaTarowCollection.Remove(DaTarow row) at MvcMiniProfiler.MiniProfilerEF.Initialize()
解决方法
protected void Application_Start() { Logger.Info("Application start"); MiniProfilerEF.Initialize_EF42(); // ... }
" alt="File "/opt/python/anaconda3/lib/python3.7/subprocess.py", line 152, in
">File "/opt/python/anaconda3/lib/python3.7/subprocess.py", line 152, in
import _posixsubprocess ImportError: dynamic module does not define module export function (PyInit__posixsubpro
如何解决:这要是sitepackages错啦,我之前赔了2.7的,所以错啦
关于交互式Python:尽管line_profiler正确导入,但无法使%lprun正常工作的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android – fb:// profile / {userid}似乎无法正常工作、asp.net – 如何使用AspNetSqlMembershipProvider正确验证mvc-mini-profiler、c# – MvcMiniProfiler无法转换EFProfiledDbConnection类型的对象、File "/opt/python/anaconda3/lib/python3.7/subprocess.py", line 152, in
本文标签: