Attach to process instead of Dispatch - com

I am using pywin32 and calling the Dispatch function to create a COM object, but this means a new instance of the application is created (in this case PTV Vissim) whenever I call the function. Is it possible, instead, to attach to an already existing Vissim application? This would speed up development, since I wouldn't have to wait for the application to start every time I run a test.
This is my existing relevant code:
import win32com.client as com
Vissim = com.Dispatch("Vissim.Vissim.540")

Specifically for PTV Vissim, there is an option to start Vissim with the extension -automation (for example: vissim100.exe -automation). If you start PTV Vissim with the extension -automation, it provides PTV Vissim as a COM server in the automation mode for COM scripts that are started subsequently.
See chapter "Starting PTV Vissim via the command prompt" of the PTV Vissim Help.

In general, you can not "attach" to an existing Vissim instance as a COM server. Each client connection should be at best backed-up by an independent Vissim instance.
That being said, it is still possible to accomplish your goal, that is - use the command line switch "-automation" to launch Vissim.exe, and that running Vissim.exe will act as an automation server as you desired.
--
What is under-the-hood?
The truth is, right in Vissim.exe's startup code, CoRegisterClassObject(CLSID, pUnk, dwClsContext, flags, &dwRegister) is by default called with flag = REGCLS_SINGLEUSE.
REGCLS_SINGLEUSE simply means, after a client application has been connected to an Vissim class object as hosted by a running Vissim.exe, the Vissim class object's class factory is removed from public view (i.e., not in the OS system's Class Table anymore). This means, a new client connection will have to launch a new Vissim instance in order to obtain the class factory, hence the creation of a new Vissim instance is in order.
However, if you use the command line switch "-automation" while launching a Vissim.exe instance, that Vissim.exe will use REGCLS_MULTIPLEUSE flag to register the class factory instead. That allows multiple client connections to the same running Vissim.exe instance afterwards.
I have more detailed blog on this matter and other relevant issues here. You might want to check them out at blog.wupingxin.net

Related

JProfiler: Why Proxy class not display in the call tree?

If I define filter with default compact config
I can see the invocation like this in the call tree-1 (this is a feign client method)
But if I define filter profiled all my source package
I can't see any invocation in the call tree-2
Actually, I wish it better to see a tree node display a proxy class call hello() like this
call stack
How could I do? Jprofiler doc say if a profiled record show in first line, all other class is compact, so I think the proxy class auto generated is compact too, why this proxy class did not show in the call tree?
Try with Dr. Ingo Kegel's answer, and got call tree-3. proxy class call feign.ReflectiveFeign$FeignInvocationHandler, why proxy disappeared?
If you define the call tree filters to com.example., neither $Proxy... nor ReflectiveFeing$FeingInvocationHandler are in the profiled classes. This means that calls into such methods will go into the inherent time of the node of the last profiled class (com.example....helloA in this case) and not have separate nodes.
With instrumentation, JProfiler does not record complete call stacks for CPU profiling. If you switch to sampling, you can disable all filters and get complete call stacks.

Geode region[key] get triggers region listener create event

Using Geode 1.2 and 9.1 Pivotal native client the following code:
IRegion<string, IPdxInstance> r = cache.GetRegion<string, IPdxInstance>("myRegion");
return r[key];
then triggers an AfterCreate event for myRegion. Why does that happen when no data is created, only read?
Same here, never used Native Client. I agreed with what #Urizen suspected - you are calling r[key] from an instance of Geode that doesn't have the entry, so it pulls the data from other instance, which "create" the entry locally.
You have a few options here:
Performing an interest registration for the instance you are initiating the call using registerAllKeys() (doc here). There is a catch here: (might not be applicable for native client), in Java API, you have an option to register interest with an InterestResultPolicy. If you use KEYS_VALUES, you will load all data to local from remote on startup WITHOUT triggering afterCreate callback. If you choose KEYS only or NONE, you will likely have similar problem.
You can check for boolean flag remoteOrigin in EntryEvent. If it is false, it is purely local. In a non-WAN setup, this should be enough to distinguish your local operation from remotely initiated operation (be it a cache syncing or a genuine creation initiated by other cache). Vaguely remembering WAN works a bit different here.
I've never used the Native Client but, at a first glance, it should be expected for the afterCreate event to be invoked on the client side as the entry is actually being created on the local cache. What I mean is that the entry might exists on the server but, internally, the client needs to retrieve it from the server, and then create it locally (thus invoking the afterCreate for the locally installed CacheListener). Makes sense?.

MarshalByRefObject causing C++ program to hang

I have a client program that uses a MarshalByRefObject to get a variable from a remote server. Sometimes the program hoses up on the remote server and when I try to get that variable my client program simply hangs. Is there a way to time out the call on this variable?
MyClass^ refObject = (MyClass^)System::Activator::GetObject(MyClass::typeid, url);
THEVARIABLE objectVariable = refObject->theVariable;
The only way I see is to implement an IMessageFilter (COM). In some cases it is possible to detect that there is an out of process call from the current STA to another. But AFAIK this is only done when an input message (keyboard/mouse) arrives.
With a message filter you can show something like "waiting for external com call...". Also in this case you may abort the external call.
See CoRegisterMessageFilter, and IMessageFilter

Object instances in App Engine

I am developing a site using App Engine and Webapp2.
I understand the concepts of OO and more or less how they are applied in Python. However I am confused about how App Engine uses OO. When an instance of my app is created, is one instance of each class created and re-used for each user? Or are separate instances created for each user? This will decide whether I should use instance or class variables.
So to be even more specific, when should I use self. variables (instance variables) and when should I leave out self. (class variables)?
Thanks for your help. :)
I would separate the concepts of object-orientation (OO) and request handling. First and foremost, App Engine is based on a request-driven model. A request is the base for most actions triggered on App Engine.
Second of all, be aware of the differences between an App Engine instance[0], which is like a container for you application and provided by the App Engine infrastructure, and an webapp2.WSGIApplication[1], which is an object instance of a class you defined.
To simplify things, I assume your app only has 1 webapp2.WSGIApplication . Now let's start with the first request your application gets. Before that, nothing of your app exists, except the code and configuration available on App Engine machines. Once the request reaches App Engine, a new App Engine instance[0] is created. Once the App Engine instance is in place and set up, it will instantiate a webapp2.WSGIApplication instance[1]. Now you have both relevant "instances" in place, the object being a part of the container. Next, the incoming request is routed to your webapp2.WSGIApplication instance which will handle the request according to the implementation you have done.
The App Engine system will create new App Engine instances for you dependening on the load. If a single instance is not able to handle all the requests that come in, it will create a new instance(first [0], then [1] within the former) and spread the load. If that's still not enough, a third instance is created and so on. The same is true if load decreases. If you application is currently running on 3 instances, but 2 would be enough to handle the load, 1 instance will be killed. In addition, you don't know which particular instance will handle which request.
And this leads us to your second question, should you depend on instance variables. Because App Engine creates and kills instances as it seems appropriate and you don't know which instance handles a request, you should always assume instances to be stateless. While it is not always the case, potentially every request can be handled by a completely new instance.
If you need to have state, use memcache (volatile) or datastore (persistent) or some other data backend (blobstore, files API, and so on).
[0] https://developers.google.com/appengine/docs/adminconsole/instances
[1] http://webapp-improved.appspot.com/guide/app.html
PS: people do use instance memory to optimize requests, but beginners who start to learn about App Engine should consider this an advanced technique.

Are node.js module variables shared across multiple invocation?

i m creating a node.js server, where i have a "notifications" module. Every request on the node server will invoke this module and i need to have a set of private variables for each separate invocation.
For example, when a request is made to notifications module, it needs to remember the user id, request time, session id, etc.
How can i do that efficiently?
If i simple declare variables in module scope, they seem to be shared for each module invocation. So, it fails in remembering every request's data privately.
What i need is each time i invoke a node.js module, it will remember its data at that time. So, please point out how can i do that?
Thanks,
Anjan
Update
The node.js server is to uses as a chat server. the "notifications" module will scan the db for new messages and send the output in json format to the client using long polling technique.
I tried to wrap the data and the functions into an object. Then each time a request is made to chat server a new object will be created and it will carry on the desired functions. But what it did is that instead of working in parallel it executes each request in serial. So, if i make 3 request to the server, they just queue up and executes one after another.
Any clue on that?
The module source code can be found here: http://www.ultrasoftbd.com/notifications.js
Thanks,
Anjan
There are a couple ways that come to mind to approach this issue:
1) Have your module export a constructor which can be called by the API users of your module to give them a new instance of an object. This way, each user will have its own object instance which has its own private variables.
// Client example.
var mod = require('myModule')
, sess = new mod.Session();
sess.method(args);
sess.finalize();
2) Have your module provide a "registry" interface to these private variables which includes an identifier unique to the caller.
// Client example.
var mod = require('myModule');
var id = mod.initialize(); // Returns a unique ID.
mod.method(id, args); // Each method requires the ID.
mod.finalize(id);
These solutions share the idea that each instance (or ID) is tracked separately by your module so that the statistics (or whatever your module does) can be computed per client instance rather than globally to the module.